@Test public void resolveFilterTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.FILTER); question.setFilterSpecifierInput(_filter1.getName()); assertThat( resolveFilter(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_NODE, new Node(_c1.getHostname()), COL_FILTER_NAME, _filter1.getName())))); question.setNodeSpecifierInput("foofoo"); assertThat( resolveFilter(question, _context).getRows().getData(), equalTo(ImmutableMultiset.of())); }
@VisibleForTesting static TableAnswerElement resolveFilter(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata(COL_NODE, Schema.NODE, "Node", false, false), new ColumnMetadata(COL_FILTER_NAME, Schema.STRING, "Filter name", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); FilterSpecifier filterSpecifier = question.getFilterSpecifier(); Set<String> nodes = question.getNodeSpecifier().resolve(context); for (String node : nodes) { Set<IpAccessList> nodeFilters = filterSpecifier.resolve(node, context); for (IpAccessList filter : nodeFilters) { table.addRow( Row.of( columnMap, COL_NODE, new Node(node), COL_FILTER_NAME, Objects.toString(filter.getName()))); } } return table; }
SpecifiersAnswerer extends Answerer { @VisibleForTesting static TableAnswerElement resolveFilter(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata(COL_NODE, Schema.NODE, "Node", false, false), new ColumnMetadata(COL_FILTER_NAME, Schema.STRING, "Filter name", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); FilterSpecifier filterSpecifier = question.getFilterSpecifier(); Set<String> nodes = question.getNodeSpecifier().resolve(context); for (String node : nodes) { Set<IpAccessList> nodeFilters = filterSpecifier.resolve(node, context); for (IpAccessList filter : nodeFilters) { table.addRow( Row.of( columnMap, COL_NODE, new Node(node), COL_FILTER_NAME, Objects.toString(filter.getName()))); } } return table; } }
SpecifiersAnswerer extends Answerer { @VisibleForTesting static TableAnswerElement resolveFilter(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata(COL_NODE, Schema.NODE, "Node", false, false), new ColumnMetadata(COL_FILTER_NAME, Schema.STRING, "Filter name", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); FilterSpecifier filterSpecifier = question.getFilterSpecifier(); Set<String> nodes = question.getNodeSpecifier().resolve(context); for (String node : nodes) { Set<IpAccessList> nodeFilters = filterSpecifier.resolve(node, context); for (IpAccessList filter : nodeFilters) { table.addRow( Row.of( columnMap, COL_NODE, new Node(node), COL_FILTER_NAME, Objects.toString(filter.getName()))); } } return table; } SpecifiersAnswerer(Question question, IBatfish batfish); }
SpecifiersAnswerer extends Answerer { @VisibleForTesting static TableAnswerElement resolveFilter(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata(COL_NODE, Schema.NODE, "Node", false, false), new ColumnMetadata(COL_FILTER_NAME, Schema.STRING, "Filter name", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); FilterSpecifier filterSpecifier = question.getFilterSpecifier(); Set<String> nodes = question.getNodeSpecifier().resolve(context); for (String node : nodes) { Set<IpAccessList> nodeFilters = filterSpecifier.resolve(node, context); for (IpAccessList filter : nodeFilters) { table.addRow( Row.of( columnMap, COL_NODE, new Node(node), COL_FILTER_NAME, Objects.toString(filter.getName()))); } } return table; } SpecifiersAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
SpecifiersAnswerer extends Answerer { @VisibleForTesting static TableAnswerElement resolveFilter(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata(COL_NODE, Schema.NODE, "Node", false, false), new ColumnMetadata(COL_FILTER_NAME, Schema.STRING, "Filter name", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); FilterSpecifier filterSpecifier = question.getFilterSpecifier(); Set<String> nodes = question.getNodeSpecifier().resolve(context); for (String node : nodes) { Set<IpAccessList> nodeFilters = filterSpecifier.resolve(node, context); for (IpAccessList filter : nodeFilters) { table.addRow( Row.of( columnMap, COL_NODE, new Node(node), COL_FILTER_NAME, Objects.toString(filter.getName()))); } } return table; } SpecifiersAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); static final String COL_FILTER_NAME; static final String COL_INTERFACE; static final String COL_IP_SPACE; static final String COL_LOCATION; static final String COL_LOCATIONS; static final String COL_NODE; }