@Test public void getProperties() { String property1 = NodePropertySpecifier.CONFIGURATION_FORMAT; String property2 = NodePropertySpecifier.NTP_SERVERS; NodePropertySpecifier propertySpec = new NodePropertySpecifier(ImmutableSet.of(property1, property2)); Configuration conf1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Configuration conf2 = new Configuration("node2", ConfigurationFormat.HOST); conf2.setNtpServers(ImmutableSortedSet.of("sa")); Map<String, Configuration> configurations = ImmutableMap.of("node1", conf1, "node2", conf2); Map<String, ColumnMetadata> columns = NodePropertiesAnswerer.createTableMetadata(new NodePropertiesQuestion(null, propertySpec)) .toColumnMap(); NodeSpecifier nodeSpecifier = new NameRegexNodeSpecifier(Pattern.compile("node1|node2")); MockSpecifierContext ctxt = MockSpecifierContext.builder().setConfigs(configurations).build(); Multiset<Row> propertyRows = NodePropertiesAnswerer.getProperties(propertySpec, ctxt, nodeSpecifier, columns); Multiset<Row> expected = HashMultiset.create( ImmutableList.of( Row.builder() .put(NodePropertiesAnswerer.COL_NODE, new Node("node1")) .put(property1, ConfigurationFormat.CISCO_IOS) .put(property2, ImmutableList.of()) .build(), Row.builder() .put(NodePropertiesAnswerer.COL_NODE, new Node("node2")) .put(property1, ConfigurationFormat.HOST) .put(property2, ImmutableList.of("sa")) .build())); assertThat(propertyRows, equalTo(expected)); }
public static Multiset<Row> getProperties( NodePropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columns) { Multiset<Row> rows = HashMultiset.create(); for (String nodeName : nodeSpecifier.resolve(ctxt)) { RowBuilder row = Row.builder(columns).put(COL_NODE, new Node(nodeName)); for (String property : propertySpecifier.getMatchingProperties()) { PropertySpecifier.fillProperty( NodePropertySpecifier.getPropertyDescriptor(property), ctxt.getConfigs().get(nodeName), property, row); } rows.add(row.build()); } return rows; }
NodePropertiesAnswerer extends Answerer { public static Multiset<Row> getProperties( NodePropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columns) { Multiset<Row> rows = HashMultiset.create(); for (String nodeName : nodeSpecifier.resolve(ctxt)) { RowBuilder row = Row.builder(columns).put(COL_NODE, new Node(nodeName)); for (String property : propertySpecifier.getMatchingProperties()) { PropertySpecifier.fillProperty( NodePropertySpecifier.getPropertyDescriptor(property), ctxt.getConfigs().get(nodeName), property, row); } rows.add(row.build()); } return rows; } }
NodePropertiesAnswerer extends Answerer { public static Multiset<Row> getProperties( NodePropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columns) { Multiset<Row> rows = HashMultiset.create(); for (String nodeName : nodeSpecifier.resolve(ctxt)) { RowBuilder row = Row.builder(columns).put(COL_NODE, new Node(nodeName)); for (String property : propertySpecifier.getMatchingProperties()) { PropertySpecifier.fillProperty( NodePropertySpecifier.getPropertyDescriptor(property), ctxt.getConfigs().get(nodeName), property, row); } rows.add(row.build()); } return rows; } NodePropertiesAnswerer(Question question, IBatfish batfish); }
NodePropertiesAnswerer extends Answerer { public static Multiset<Row> getProperties( NodePropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columns) { Multiset<Row> rows = HashMultiset.create(); for (String nodeName : nodeSpecifier.resolve(ctxt)) { RowBuilder row = Row.builder(columns).put(COL_NODE, new Node(nodeName)); for (String property : propertySpecifier.getMatchingProperties()) { PropertySpecifier.fillProperty( NodePropertySpecifier.getPropertyDescriptor(property), ctxt.getConfigs().get(nodeName), property, row); } rows.add(row.build()); } return rows; } NodePropertiesAnswerer(Question question, IBatfish batfish); static List<ColumnMetadata> createColumnMetadata(NodePropertySpecifier propertySpecifier); @Override TableAnswerElement answer(NetworkSnapshot snapshot); static Multiset<Row> getProperties(
      NodePropertySpecifier propertySpecifier,
      SpecifierContext ctxt,
      NodeSpecifier nodeSpecifier,
      Map<String, ColumnMetadata> columns); static String getColumnName(String property); }
NodePropertiesAnswerer extends Answerer { public static Multiset<Row> getProperties( NodePropertySpecifier propertySpecifier, SpecifierContext ctxt, NodeSpecifier nodeSpecifier, Map<String, ColumnMetadata> columns) { Multiset<Row> rows = HashMultiset.create(); for (String nodeName : nodeSpecifier.resolve(ctxt)) { RowBuilder row = Row.builder(columns).put(COL_NODE, new Node(nodeName)); for (String property : propertySpecifier.getMatchingProperties()) { PropertySpecifier.fillProperty( NodePropertySpecifier.getPropertyDescriptor(property), ctxt.getConfigs().get(nodeName), property, row); } rows.add(row.build()); } return rows; } NodePropertiesAnswerer(Question question, IBatfish batfish); static List<ColumnMetadata> createColumnMetadata(NodePropertySpecifier propertySpecifier); @Override TableAnswerElement answer(NetworkSnapshot snapshot); static Multiset<Row> getProperties(
      NodePropertySpecifier propertySpecifier,
      SpecifierContext ctxt,
      NodeSpecifier nodeSpecifier,
      Map<String, ColumnMetadata> columns); static String getColumnName(String property); static final String COL_NODE; }