public InterfaceGroup toInterfaceGroup() { return new InterfaceGroup( ImmutableSortedSet.copyOf(firstNonNull(interfaces, ImmutableSet.of())), name); } }
public InterfaceGroupBean(InterfaceGroup interfaceGroup) { name = interfaceGroup.getName(); interfaces = ImmutableSet.copyOf(interfaceGroup.getInterfaces()); }
/** Return the {@link InterfaceGroup} with name {@code groupName} */ public Optional<InterfaceGroup> getInterfaceGroup(String groupName) { return _interfaceGroups.stream().filter(group -> group.getName().equals(groupName)).findAny(); }
@Override public Set<Interface> resolve(Set<String> nodes, SpecifierContext ctxt) { InterfaceGroup interfaceGroup = ctxt.getReferenceBook(_bookName) .orElseThrow( () -> new NoSuchElementException("ReferenceBook '" + _bookName + "' not found")) .getInterfaceGroup(_interfaceGroupName) .orElseThrow( () -> new NoSuchElementException( "InterfaceGroup '" + _interfaceGroupName + "' not found in ReferenceBook '" + _bookName + "'")); return nodes.stream() .map(n -> ctxt.getConfigs().get(n).getAllInterfaces().values()) .flatMap(Collection::stream) // we have a stream of Interfaces now .filter( v -> interfaceGroup .getInterfaces() .contains(new NodeInterfacePair(v.getOwner().getHostname(), v.getName()))) .collect(Collectors.toSet()); } }
@JsonCreator private static InterfaceGroup jsonCreator( @JsonProperty(PROP_INTERFACES) SortedSet<NodeInterfacePair> interfaces, @JsonProperty(PROP_NAME) String name) { checkArgument(name != null, "Interface group name cannot not be null"); return new InterfaceGroup(firstNonNull(interfaces, ImmutableSortedSet.of()), name); }
@Test public void constructorNonEmptyBook() { ReferenceBook book2 = ReferenceBook.builder("book2") .setAddressGroups(ImmutableList.of(new AddressGroup(ImmutableSortedSet.of(), "ag1"))) .setFilterGroups(ImmutableList.of(new FilterGroup(ImmutableList.of(), "fg1"))) .setInterfaceGroups( ImmutableList.of(new InterfaceGroup(ImmutableSortedSet.of(), "ig1"))) .setServiceEndpoints(ImmutableList.of(new ServiceEndpoint("ag1", "se1", "so1"))) .setServiceObjectGroups( ImmutableList.of(new ServiceObjectGroup("sog1", ImmutableSortedSet.of()))) .setServiceObjects( ImmutableList.of(new ServiceObject(IpProtocol.TCP, "so1", new SubRange(2, 3)))) .build(); beanBookMatch(new ReferenceBookBean(book2), book2); }
@Test public void toAddressBook() { ReferenceBookBean bean = new ReferenceBookBean( ReferenceBook.builder("book2") .setAddressGroups( ImmutableList.of(new AddressGroup(ImmutableSortedSet.of(), "ag1"))) .setFilterGroups(ImmutableList.of(new FilterGroup(ImmutableList.of(), "fg1"))) .setInterfaceGroups( ImmutableList.of(new InterfaceGroup(ImmutableSortedSet.of(), "ig1"))) .setServiceEndpoints(ImmutableList.of(new ServiceEndpoint("ag1", "se1", "so1"))) .setServiceObjectGroups( ImmutableList.of(new ServiceObjectGroup("sog1", ImmutableSortedSet.of()))) .setServiceObjects( ImmutableList.of(new ServiceObject(IpProtocol.TCP, "so1", new SubRange(2, 3)))) .build()); beanBookMatch(bean, bean.toAddressBook()); } }
.setInterfaceGroups( ImmutableList.of( new InterfaceGroup( ImmutableSortedSet.of( new NodeInterfacePair(node1.getHostname(), iface11.getName())),