wrap EnumSet into unmodifiableSet directly, plus minor changes
This commit is contained in:
parent
36f446759f
commit
f9a5e1a03a
|
@ -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<DiscoveryNode>, ToXContent {
|
|||
private final TransportAddress address;
|
||||
private final Map<String, String> attributes;
|
||||
private final Version version;
|
||||
private final EnumSet<Role> roles;
|
||||
private final Set<Role> roles;
|
||||
|
||||
/**
|
||||
* Creates a new {@link DiscoveryNode} by reading from the stream provided as argument
|
||||
|
@ -211,16 +212,16 @@ public class DiscoveryNode implements Writeable<DiscoveryNode>, 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<Map<String, String>> 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<Role> rolesSet = Collections.unmodifiableSet(roles);
|
||||
this.roles = EnumSet.noneOf(Role.class);
|
||||
this.roles.addAll(rolesSet);
|
||||
return true;
|
||||
};
|
||||
assert predicate.test(attributes);
|
||||
Set<Role> rolesSet = EnumSet.noneOf(Role.class);
|
||||
rolesSet.addAll(roles);
|
||||
this.roles = Collections.unmodifiableSet(rolesSet);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -364,10 +364,7 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
|
|||
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<String, String> tribeAttr = new HashMap<>();
|
||||
for (Map.Entry<String, String> entry : tribe.getAttributes().entrySet()) {
|
||||
tribeAttr.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
Map<String, String> 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());
|
||||
|
|
Loading…
Reference in New Issue