use of org.elasticsearch.cluster.node.DiscoveryNode.Role.DATA in project elasticsearch by elastic.
the class InternalTestClusterTests method testDifferentRolesMaintainPathOnRestart.
public void testDifferentRolesMaintainPathOnRestart() throws Exception {
final Path baseDir = createTempDir();
final int numNodes = 5;
InternalTestCluster cluster = new InternalTestCluster(randomLong(), baseDir, true, true, 0, 0, "test", new NodeConfigurationSource() {
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder().put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), numNodes).put(NetworkModule.HTTP_ENABLED.getKey(), false).put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), 0).build();
}
@Override
public Settings transportClientSettings() {
return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).build();
}
}, 0, randomBoolean(), "", Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class), Function.identity());
cluster.beforeTest(random(), 0.0);
try {
Map<DiscoveryNode.Role, Set<String>> pathsPerRole = new HashMap<>();
for (int i = 0; i < numNodes; i++) {
final DiscoveryNode.Role role = i == numNodes - 1 && pathsPerRole.containsKey(MASTER) == false ? // last noe and still no master ofr the cluster
MASTER : randomFrom(MASTER, DiscoveryNode.Role.DATA, DiscoveryNode.Role.INGEST);
final String node;
switch(role) {
case MASTER:
node = cluster.startMasterOnlyNode(Settings.EMPTY);
break;
case DATA:
node = cluster.startDataOnlyNode(Settings.EMPTY);
break;
case INGEST:
node = cluster.startCoordinatingOnlyNode(Settings.EMPTY);
break;
default:
throw new IllegalStateException("get your story straight");
}
Set<String> rolePaths = pathsPerRole.computeIfAbsent(role, k -> new HashSet<>());
for (Path path : getNodePaths(cluster, node)) {
assertTrue(rolePaths.add(path.toString()));
}
}
cluster.fullRestart();
Map<DiscoveryNode.Role, Set<String>> result = new HashMap<>();
for (String name : cluster.getNodeNames()) {
DiscoveryNode node = cluster.getInstance(ClusterService.class, name).localNode();
List<String> paths = Arrays.stream(getNodePaths(cluster, name)).map(Path::toString).collect(Collectors.toList());
if (node.isMasterNode()) {
result.computeIfAbsent(MASTER, k -> new HashSet<>()).addAll(paths);
} else if (node.isDataNode()) {
result.computeIfAbsent(DATA, k -> new HashSet<>()).addAll(paths);
} else {
result.computeIfAbsent(INGEST, k -> new HashSet<>()).addAll(paths);
}
}
assertThat(result.size(), equalTo(pathsPerRole.size()));
for (DiscoveryNode.Role role : result.keySet()) {
assertThat("path are not the same for " + role, result.get(role), equalTo(pathsPerRole.get(role)));
}
} finally {
cluster.close();
}
}
Aggregations