Skip to content
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 @@ -22,7 +22,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import static java.lang.Math.max;
Expand Down Expand Up @@ -90,15 +89,6 @@ private static List<String> options(int heapSize) {
* Parses role information from elasticsearch.yml and determines machine node role.
*/
static class NodeRoleParser {
private static final Set<String> LEGACY_ROLE_SETTINGS = Set.of(
"node.master",
"node.ingest",
"node.data",
"node.voting_only",
"node.ml",
"node.transform",
"node.remote_cluster_client"
);

@SuppressWarnings("unchecked")
public static MachineNodeRole parse(InputStream config) {
Expand All @@ -113,30 +103,24 @@ public static MachineNodeRole parse(InputStream config) {

if (root != null) {
Map<String, Object> map = flatten(root, null);

if (hasLegacySettings(map.keySet())) {
// We don't attempt to auto-determine heap if legacy role settings are used
return MachineNodeRole.UNKNOWN;
} else {
List<String> roles = null;
try {
if (map.containsKey("node.roles")) {
roles = (List<String>) map.get("node.roles");
}
} catch (ClassCastException ex) {
return MachineNodeRole.UNKNOWN;
List<String> roles = null;
try {
if (map.containsKey("node.roles")) {
roles = (List<String>) map.get("node.roles");
}
} catch (ClassCastException ex) {
return MachineNodeRole.UNKNOWN;
}

if (roles == null || roles.isEmpty()) {
// If roles are missing or empty (coordinating node) assume defaults and consider this a data node
return MachineNodeRole.DATA;
} else if (containsOnly(roles, "master")) {
return MachineNodeRole.MASTER_ONLY;
} else if (roles.contains("ml") && containsOnly(roles, "ml", "remote_cluster_client")) {
return MachineNodeRole.ML_ONLY;
} else {
return MachineNodeRole.DATA;
}
if (roles == null || roles.isEmpty()) {
// If roles are missing or empty (coordinating node) assume defaults and consider this a data node
return MachineNodeRole.DATA;
} else if (containsOnly(roles, "master")) {
return MachineNodeRole.MASTER_ONLY;
} else if (roles.contains("ml") && containsOnly(roles, "ml", "remote_cluster_client")) {
return MachineNodeRole.ML_ONLY;
} else {
return MachineNodeRole.DATA;
}
} else { // if the config is completely empty, then assume defaults and consider this a data node
return MachineNodeRole.DATA;
Expand Down Expand Up @@ -174,10 +158,6 @@ private static Map<String, Object> flatten(Map<String, Object> config, String pa
private static <T> boolean containsOnly(Collection<T> collection, T... items) {
return Arrays.asList(items).containsAll(collection);
}

private static boolean hasLegacySettings(Set<String> keys) {
return LEGACY_ROLE_SETTINGS.stream().anyMatch(keys::contains);
}
}

enum MachineNodeRole {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,6 @@ public void testDataNode() throws IOException {
assertThat(nodeRole, equalTo(DATA));
}

public void testLegacySettings() throws IOException {
MachineDependentHeap.MachineNodeRole nodeRole = parseConfig(sb -> sb.append("node.ml: true"));
assertThat(nodeRole, equalTo(UNKNOWN));

nodeRole = parseConfig(sb -> sb.append("node.master: true"));
assertThat(nodeRole, equalTo(UNKNOWN));

nodeRole = parseConfig(sb -> sb.append("node.data: false"));
assertThat(nodeRole, equalTo(UNKNOWN));

nodeRole = parseConfig(sb -> sb.append("node.ingest: false"));
assertThat(nodeRole, equalTo(UNKNOWN));
}

public void testYamlSyntax() throws IOException {
MachineDependentHeap.MachineNodeRole nodeRole = parseConfig(sb -> sb.append("""
node:
Expand Down