@VisibleForTesting static Set<String> computeEmptyColumns(TableAnswerElement table) { return table.getMetadata().toColumnMap().keySet().stream() .filter(column -> table.getRowsList().stream().allMatch(row -> !row.hasNonNull(column))) .collect(ImmutableSet.toImmutableSet()); }
private static TableAnswerElement toSearchFiltersTable( TableAnswerElement tableAnswerElement, boolean generateExplanation) { Map<String, ColumnMetadata> columnMap = tableAnswerElement.getMetadata().toColumnMap(); List<ColumnMetadata> columnMetadata = new ArrayList<>(); columnMetadata.add(columnMap.get(TestFiltersAnswerer.COL_NODE)); columnMetadata.add(columnMap.get(TestFiltersAnswerer.COL_FILTER_NAME)); if (generateExplanation) { columnMetadata.add( new ColumnMetadata(COL_HEADER_SPACE, Schema.STRING, "Description of HeaderSpace")); } columnMetadata.add(columnMap.get(TestFiltersAnswerer.COL_FLOW)); columnMetadata.add(columnMap.get(TestFiltersAnswerer.COL_ACTION)); columnMetadata.add(columnMap.get(TestFiltersAnswerer.COL_LINE_CONTENT)); columnMetadata.add(columnMap.get(TestFiltersAnswerer.COL_TRACE)); TableMetadata metadata = new TableMetadata(columnMetadata); return new TableAnswerElement(metadata); }
@VisibleForTesting static @Nonnull Map<String, MajorIssueConfig> computeMajorIssueConfigs(TableAnswerElement table) { Map<String, ImmutableList.Builder<MinorIssueConfig>> majorIssueConfigs = new HashMap<>(); // For every issue column of every row, extract the issue and use it to update the map table.getMetadata().getColumnMetadata().stream() .filter(c -> c.getSchema().equals(Schema.ISSUE)) .map(ColumnMetadata::getName) .flatMap( column -> table.getRowsList().stream() .filter(row -> row.hasNonNull(column)) .map(row -> row.getIssue(column))) .forEach( issue -> majorIssueConfigs .computeIfAbsent(issue.getType().getMajor(), m -> ImmutableList.builder()) .add( new MinorIssueConfig( issue.getType().getMinor(), issue.getSeverity(), issue.getUrl()))); return CommonUtil.toImmutableMap( majorIssueConfigs, Entry::getKey, // major issue type e -> new MajorIssueConfig(e.getKey(), e.getValue().build())); }
static Integer computeColumnMax( @Nonnull TableAnswerElement table, @Nonnull String column, @Nonnull BatfishLogger logger) { ColumnMetadata columnMetadata = table.getMetadata().toColumnMap().get(column); if (columnMetadata == null) { String message = String.format("No column named: %s", column);
@VisibleForTesting static TableAnswerElement resolveLocation(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata(COL_LOCATION, Schema.STRING, "Location", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); Set<Location> locations = question.getLocationSpecifier().resolve(context); for (Location location : locations) { table.addRow(Row.of(columnMap, COL_LOCATION, location.toString())); } return table; }
table.getExcludedRows().stream().map(ExcludedRows::getRowsList).mapToInt(List::size).sum(); ImmutableList.Builder<ColumnAggregation> columnAggregationsBuilder = ImmutableList.builder(); table.getMetadata().getColumnMetadata().stream() .map(ColumnMetadata::getName) .forEach(
@Test public void testTableAnswerElementColumns() { AaaAuthenticationLoginQuestion question = new AaaAuthenticationLoginQuestion(); TableAnswerElement tableAnswerElement = AaaAuthenticationLoginAnswerer.create(question); Set<String> columnNames = tableAnswerElement.getMetadata().getColumnMetadata().stream() .map(ColumnMetadata::getName) .collect(ImmutableSet.toImmutableSet()); assertThat(columnNames, equalTo(ImmutableSet.of(COLUMN_NODE, COLUMN_LINE_NAMES))); } }
@VisibleForTesting @Nonnull TableAnswerElement processAnswerTable(TableAnswerElement rawTable, AnswerRowsOptions options) { Map<String, ColumnMetadata> rawColumnMap = rawTable.getMetadata().toColumnMap(); List<Row> filteredRows = rawTable.getRowsList().stream() table = new TableAnswerElement(rawTable.getMetadata()); } else { table = new TableAnswerElement( new TableMetadata(columnMetadata, rawTable.getMetadata().getTextDesc()));
/** Adds {@code nodes} (which are present in only one snapshot) to the {@code table} */ private void addOneSnapshotNodes(SetView<String> nodes, TableAnswerElement table) { for (String node : nodes) { table.addRow(Row.builder(table.getMetadata().toColumnMap()).put(COL_NODE, node).build()); } } }
Map<Row, Integer> rowIds = Maps.newIdentityHashMap(); CommonUtil.forEachWithIndex(rawTable.getRowsList(), (i, row) -> rowIds.put(row, i)); Map<String, ColumnMetadata> rawColumnMap = rawTable.getMetadata().toColumnMap(); List<Row> filteredRows = rawTable.getRowsList().stream() tableMetadata = rawTable.getMetadata(); } else { List<ColumnMetadata> columnMetadata = columnMap.values().stream().collect(ImmutableList.toImmutableList()); tableMetadata = new TableMetadata(columnMetadata, rawTable.getMetadata().getTextDesc());
.readValue(_storage.loadAnswer(baseAnswerId), new TypeReference<Answer>() {}); TableAnswerElement oldTable = (TableAnswerElement) oldAnswer.getAnswerElements().get(0); TableMetadata tableMetadata = oldTable.getMetadata(); Set<String> issueColumns = tableMetadata.getColumnMetadata().stream()
@VisibleForTesting static TableAnswerElement resolveNode(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata(COL_NODE, Schema.NODE, "Node", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); Set<String> nodes = question.getNodeSpecifier().resolve(context); for (String node : nodes) { table.addRow(Row.of(columnMap, COL_NODE, new Node(node))); } return table; } }
@VisibleForTesting static TableAnswerElement resolveIpSpace(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata(COL_IP_SPACE, Schema.STRING, "IP space", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); // this will yield all default locations for the factory Set<Location> locations = question.getLocationSpecifier().resolve(context); IpSpaceAssignment ipSpaceAssignment = question.getIpSpaceSpecifier().resolve(locations, context); for (IpSpaceAssignment.Entry entry : ipSpaceAssignment.getEntries()) { table.addRow(Row.of(columnMap, COL_IP_SPACE, Objects.toString(entry.getIpSpace()))); } return table; }
checkArgument( baseTable .getMetadata() .getColumnMetadata() .equals(deltaTable.getMetadata().getColumnMetadata()), "Cannot diff tables with different column metadatas"); TableMetadata inputMetadata = baseTable.getMetadata(); TableAnswerElement diffTable = new TableAnswerElement(diffMetadata(inputMetadata)); Map<String, ColumnMetadata> diffColumnMap = diffTable.getMetadata().toColumnMap();
@VisibleForTesting static TableAnswerElement resolveIpSpaceOfLocation( SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata(COL_LOCATIONS, Schema.STRING, "Resolution", false, false), new ColumnMetadata(COL_IP_SPACE, Schema.STRING, "IP space", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); Set<Location> locations = question.getLocationSpecifier().resolve(context); IpSpaceAssignment ipSpaceAssignment = question.getIpSpaceSpecifier().resolve(locations, context); for (IpSpaceAssignment.Entry entry : ipSpaceAssignment.getEntries()) { table.addRow( Row.of( columnMap, COL_LOCATIONS, entry.getLocations().toString(), COL_IP_SPACE, Objects.toString(entry.getIpSpace()))); } return table; }
@VisibleForTesting static TableAnswerElement resolveInterface( SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata(COL_INTERFACE, Schema.INTERFACE, "Interface", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); InterfaceSpecifier interfaceSpecifier = question.getInterfaceSpecifier(); Set<String> nodes = question.getNodeSpecifier().resolve(context); Set<Interface> interfaces = interfaceSpecifier.resolve(nodes, context); for (Interface iface : interfaces) { table.addRow(Row.of(columnMap, COL_INTERFACE, new NodeInterfacePair(iface))); } return table; }
Row.builder(baseTable.getMetadata().toColumnMap()) .put(COL_NODE, node) .put(COL_FILTER_NAME, aclName) Row.builder(deltaTable.getMetadata().toColumnMap()) .put(COL_NODE, node) .put(COL_FILTER_NAME, aclName) TableDiff.diffTables(baseTable, deltaTable, question.getIncludeOneTableKeys()); _tableAnswerElement = new TableAnswerElement(diffTable.getMetadata()); _tableAnswerElement.postProcessAnswer(question, diffTable.getRows().getData());
@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; }
@Override public AnswerElement answer() { FilterTableQuestion question = (FilterTableQuestion) _question; Question innerQuestion = question.getInnerQuestion(); AnswerElement innerAnswer = _batfish.createAnswerer(innerQuestion).answer(); if (!(innerAnswer instanceof TableAnswerElement)) { throw new IllegalArgumentException("The inner question does not produce table answers"); } TableAnswerElement innerTable = (TableAnswerElement) innerAnswer; TableAnswerElement answer = new TableAnswerElement(createMetadata(question, innerTable.getMetadata())); Multiset<Row> answerRows = innerTable.getRows().getData(); if (question.getFilter() != null) { answerRows = filterRows(question.getFilter(), answerRows); } if (question.getColumns() != null) { answerRows = selectColumns(question.getColumns(), answerRows); } answer.postProcessAnswer(question, answerRows); return answer; }
(TableAnswerElement) deltaAnswer, _question.getIncludeOneTableKeys()); TableAnswerElement finalTable = new TableAnswerElement(rawTable.getMetadata()); finalTable.postProcessAnswer(_question, rawTable.getRows().getData()); return finalTable;