diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index a816a721f3f..79fa04460b7 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -38,6 +38,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Predicate; import static org.elasticsearch.common.transport.TransportAddressSerializers.addressToStream; @@ -88,7 +89,7 @@ public class DiscoveryNode implements Writeable, ToXContent { private final TransportAddress address; private final Map attributes; private final Version version; - private final EnumSet roles; + private final Set roles; /** * Creates a new {@link DiscoveryNode} by reading from the stream provided as argument @@ -211,16 +212,16 @@ public class DiscoveryNode implements Writeable, ToXContent { } this.attributes = Collections.unmodifiableMap(attributes); //verify that no node roles are being provided as attributes - boolean assertEnabled = false; - assert assertEnabled = true; - if (assertEnabled) { + Predicate> predicate = (attrs) -> { for (Role role : Role.values()) { - assert attributes.containsKey(role.getRoleName()) == false : "role name [" + role.getRoleName() + "] found in attributes"; + assert attrs.containsKey(role.getRoleName()) == false; } - } - Set rolesSet = Collections.unmodifiableSet(roles); - this.roles = EnumSet.noneOf(Role.class); - this.roles.addAll(rolesSet); + return true; + }; + assert predicate.test(attributes); + Set rolesSet = EnumSet.noneOf(Role.class); + rolesSet.addAll(roles); + this.roles = Collections.unmodifiableSet(rolesSet); } /** diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java index aa5397825cb..a31624c5175 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -364,10 +364,7 @@ public class TribeService extends AbstractLifecycleComponent { for (DiscoveryNode tribe : tribeState.nodes()) { if (currentState.nodes().get(tribe.id()) == null) { // a new node, add it, but also add the tribe name to the attributes - Map tribeAttr = new HashMap<>(); - for (Map.Entry entry : tribe.getAttributes().entrySet()) { - tribeAttr.put(entry.getKey(), entry.getValue()); - } + Map tribeAttr = new HashMap<>(tribe.getAttributes()); tribeAttr.put(TRIBE_NAME_SETTING.getKey(), tribeName); DiscoveryNode discoNode = new DiscoveryNode(tribe.name(), tribe.id(), tribe.getHostName(), tribe.getHostAddress(), tribe.address(), unmodifiableMap(tribeAttr), tribe.getRoles(), tribe.version());