@Test public void resolve() { Configuration node1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Configuration node2 = new Configuration("node2", ConfigurationFormat.CISCO_IOS); Interface iface11 = Interface.builder().setName("iface1").setOwner(node1).build(); Interface iface12 = Interface.builder().setName("iface2").setOwner(node1).build(); Interface iface21 = Interface.builder().setName("iface1").setOwner(node2).build(); node1.setInterfaces( ImmutableSortedMap.of(iface11.getName(), iface11, iface12.getName(), iface12)); node2.setInterfaces(ImmutableSortedMap.of(iface21.getName(), iface21)); ReferenceBook referenceBook = ReferenceBook.builder("refbook") .setInterfaceGroups( ImmutableList.of( new InterfaceGroup( ImmutableSortedSet.of( NodeInterfacePair.of(node1.getHostname(), iface11.getName())), "group"))) .build(); MockSpecifierContext ctxt = MockSpecifierContext.builder() .setConfigs(ImmutableMap.of(node1.getHostname(), node1, node2.getHostname(), node2)) .setReferenceBooks(ImmutableSortedSet.of(referenceBook)) .build(); assertThat( new ReferenceInterfaceGroupInterfaceSpecifier("group", "refbook") .resolve(ImmutableSet.of(node1.getHostname()), ctxt), contains(NodeInterfacePair.of(iface11))); }
@Override public Set<NodeInterfacePair> 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) .map(NodeInterfacePair::of) .filter(interfaceGroup.getInterfaces()::contains) .collect(ImmutableSet.toImmutableSet()); }
ReferenceInterfaceGroupInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> 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) .map(NodeInterfacePair::of) .filter(interfaceGroup.getInterfaces()::contains) .collect(ImmutableSet.toImmutableSet()); } }
ReferenceInterfaceGroupInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> 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) .map(NodeInterfacePair::of) .filter(interfaceGroup.getInterfaces()::contains) .collect(ImmutableSet.toImmutableSet()); } ReferenceInterfaceGroupInterfaceSpecifier(String interfaceGroupName, String bookName); }
ReferenceInterfaceGroupInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> 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) .map(NodeInterfacePair::of) .filter(interfaceGroup.getInterfaces()::contains) .collect(ImmutableSet.toImmutableSet()); } ReferenceInterfaceGroupInterfaceSpecifier(String interfaceGroupName, String bookName); @Override boolean equals(Object o); @Override int hashCode(); @Override Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt); }
ReferenceInterfaceGroupInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> 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) .map(NodeInterfacePair::of) .filter(interfaceGroup.getInterfaces()::contains) .collect(ImmutableSet.toImmutableSet()); } ReferenceInterfaceGroupInterfaceSpecifier(String interfaceGroupName, String bookName); @Override boolean equals(Object o); @Override int hashCode(); @Override Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt);  }