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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static org.elasticsearch.common.transport.TransportAddressSerializers.addressToStream;
|
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 TransportAddress address;
|
||||||
private final Map<String, String> attributes;
|
private final Map<String, String> attributes;
|
||||||
private final Version version;
|
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
|
* 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);
|
this.attributes = Collections.unmodifiableMap(attributes);
|
||||||
//verify that no node roles are being provided as attributes
|
//verify that no node roles are being provided as attributes
|
||||||
boolean assertEnabled = false;
|
Predicate<Map<String, String>> predicate = (attrs) -> {
|
||||||
assert assertEnabled = true;
|
|
||||||
if (assertEnabled) {
|
|
||||||
for (Role role : Role.values()) {
|
for (Role role : Role.values()) {
|
||||||
assert attributes.containsKey(role.getRoleName()) == false : "role name [" + role.getRoleName() + "] found in attributes";
|
assert attrs.containsKey(role.getRoleName()) == false;
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
Set<Role> rolesSet = Collections.unmodifiableSet(roles);
|
};
|
||||||
this.roles = EnumSet.noneOf(Role.class);
|
assert predicate.test(attributes);
|
||||||
this.roles.addAll(rolesSet);
|
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()) {
|
for (DiscoveryNode tribe : tribeState.nodes()) {
|
||||||
if (currentState.nodes().get(tribe.id()) == null) {
|
if (currentState.nodes().get(tribe.id()) == null) {
|
||||||
// a new node, add it, but also add the tribe name to the attributes
|
// a new node, add it, but also add the tribe name to the attributes
|
||||||
Map<String, String> tribeAttr = new HashMap<>();
|
Map<String, String> tribeAttr = new HashMap<>(tribe.getAttributes());
|
||||||
for (Map.Entry<String, String> entry : tribe.getAttributes().entrySet()) {
|
|
||||||
tribeAttr.put(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
tribeAttr.put(TRIBE_NAME_SETTING.getKey(), tribeName);
|
tribeAttr.put(TRIBE_NAME_SETTING.getKey(), tribeName);
|
||||||
DiscoveryNode discoNode = new DiscoveryNode(tribe.name(), tribe.id(), tribe.getHostName(), tribe.getHostAddress(),
|
DiscoveryNode discoNode = new DiscoveryNode(tribe.name(), tribe.id(), tribe.getHostName(), tribe.getHostAddress(),
|
||||||
tribe.address(), unmodifiableMap(tribeAttr), tribe.getRoles(), tribe.version());
|
tribe.address(), unmodifiableMap(tribeAttr), tribe.getRoles(), tribe.version());
|
||||||
|
|
Loading…
Reference in New Issue