@Override public Set<String> resolve(SpecifierContext ctxt) { Optional<NodeRoleDimension> dimension = ctxt.getNodeRoleDimension(_roleDimension); Set<NodeRole> roles = dimension.isPresent() ? dimension.get().getRoles().stream() .filter(role -> _rolePattern.matcher(role.getName()).matches()) .collect(ImmutableSet.toImmutableSet()) : ImmutableSet.of(); return ctxt.getConfigs().keySet().stream() .filter(node -> roles.stream().anyMatch(role -> role.matches(node))) .collect(ImmutableSet.toImmutableSet()); } }
@Override public Set<Location> resolve(SpecifierContext ctxt) { Optional<NodeRoleDimension> dimension = ctxt.getNodeRoleDimension(_roleDimension); Set<NodeRole> matchingRoles = dimension.isPresent() ? dimension.get().getRoles().stream() .filter(role -> _rolePattern.matcher(role.getName()).matches()) .collect(ImmutableSet.toImmutableSet()) : ImmutableSet.of(); return ctxt.getConfigs().values().stream() .filter(node -> matchingRoles.stream().anyMatch(role -> role.matches(node.getHostname()))) .flatMap(this::getNodeLocations) .collect(ImmutableSet.toImmutableSet()); } }
@JsonIgnore /** Return the set of nodes that match this specifier */ public Set<String> getMatchingNodes(SpecifierContext ctxt) { switch (_type) { case NAME: return getMatchingNodesByName(ctxt.getConfigs().keySet()); case ROLE: Optional<NodeRoleDimension> roleDimension = ctxt.getNodeRoleDimension(_roleDimension); if (roleDimension.isPresent()) { return getMatchingNodesByRole(roleDimension.get(), ctxt.getConfigs().keySet()); } else { return Collections.emptySet(); } default: throw new BatfishException("Unhandled NodesSpecifier type: " + _type); } }