@Override public AnswerElement answer() { BgpSessionStatusQuestion question = (BgpSessionStatusQuestion) _question; TableAnswerElement answer = new TableAnswerElement(createMetadata(question)); answer.postProcessAnswer(question, getRows(question)); return answer; }
@Override public AnswerElement answer() { DefinedStructuresQuestion question = (DefinedStructuresQuestion) _question; Multiset<Row> structures = rawAnswer(question); TableAnswerElement answer = new TableAnswerElement(createMetadata(question)); answer.postProcessAnswer(question, structures); return answer; }
@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; }
@Override public AnswerElement answer() { IpOwnersQuestion question = (IpOwnersQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Map<Ip, Set<String>> ipNodeOwners = TopologyUtil.computeIpNodeOwners(configurations, false); Map<String, Set<Interface>> interfaces = TopologyUtil.computeNodeInterfaces(configurations); TableAnswerElement answerElement = new TableAnswerElement(getTableMetadata()); answerElement.postProcessAnswer( _question, generateRows(ipNodeOwners, interfaces, question.getDuplicatesOnly())); return answerElement; }
@Override public TableAnswerElement answer() { NamedStructuresQuestion question = (NamedStructuresQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); TableMetadata tableMetadata = createMetadata(question); Multiset<Row> propertyRows = rawAnswer(question, nodes, configurations, tableMetadata.toColumnMap()); TableAnswerElement answer = new TableAnswerElement(tableMetadata); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public AnswerElement answer() { PrefixTracerQuestion question = (PrefixTracerQuestion) _question; TableAnswerElement answer = new TableAnswerElement(getTableMetadata()); DataPlane dp = _batfish.loadDataPlane(); SortedMap<String, SortedMap<String, Map<Prefix, Map<String, Set<String>>>>> prefixTracingInfo = dp.getPrefixTracingInfoSummary(); answer.postProcessAnswer( question, getRows(prefixTracingInfo, question.getPrefix(), question.getNodes())); return answer; }
@Override public AnswerElement answer() { OspfPropertiesQuestion question = (OspfPropertiesQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getProperties(question.getProperties(), configurations, nodes, tableMetadata.toColumnMap()); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public TableAnswerElement answer() { NodePropertiesQuestion question = (NodePropertiesQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); TableMetadata tableMetadata = createTableMetadata(question); Multiset<Row> propertyRows = getProperties(question.getProperties(), configurations, nodes, tableMetadata.toColumnMap()); TableAnswerElement answer = new TableAnswerElement(tableMetadata); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public AnswerElement answer() { BgpProcessConfigurationQuestion question = (BgpProcessConfigurationQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getProperties(question.getProperties(), configurations, nodes, tableMetadata.toColumnMap()); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public TableAnswerElement answer() { VxlanVniPropertiesQuestion question = (VxlanVniPropertiesQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodeSpecifier().resolve(_batfish.specifierContext()); TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getProperties(question.getProperties(), configurations, nodes, tableMetadata.toColumnMap()); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public AnswerElement answer() { BgpPeerConfigurationQuestion question = (BgpPeerConfigurationQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodesSpecifier().resolve(_batfish.specifierContext()); TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getAnswerRows(configurations, nodes, tableMetadata.toColumnMap(), question.getProperties()); answer.postProcessAnswer(question, propertyRows); return answer; }
@Test public void testAddEmptyRow() { TableAnswerElement table = new TableAnswerElement(oneKeyTableMetadata); Row row = Row.builder().build(); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage( String.format( "Row columns %s do not match metadata columns metadata %s", row.getColumnNames(), oneKeyTableMetadata.toColumnMap().keySet())); table.addRow(row); }
@Test public void testAddRowMissingColumn() { TableAnswerElement table = new TableAnswerElement(twoKeyTableMetadata); Row row = Row.builder().put("key1", null).build(); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage( String.format( "Row columns %s do not match metadata columns metadata %s", row.getColumnNames(), twoKeyTableMetadata.toColumnMap().keySet())); table.addRow(row); }
@Test public void testComputeMajorIssueTypesNone() { String columnName = "col"; TableMetadata tableMetadata = new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.ISSUE, "foobar")), new DisplayHints().getTextDesc()); TableAnswerElement table = new TableAnswerElement(tableMetadata) .addRow(Row.builder(tableMetadata.toColumnMap()).build()); assertThat(AnswerMetadataUtil.computeMajorIssueConfigs(table), equalTo(ImmutableMap.of())); }
@Test public void testAddRowExtraColumn() { TableAnswerElement table = new TableAnswerElement(twoKeyTableMetadata); Row row = Row.builder().put("key1", null).put("key2", null).put("key3", null).build(); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage( String.format( "Row columns %s do not match metadata columns metadata %s", row.getColumnNames(), twoKeyTableMetadata.toColumnMap().keySet())); table.addRow(row); } }
@Test public void testComputeMajorIssueTypesNoColumn() { String columnName = "col"; String value = "foo"; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.STRING, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, value)); assertThat(AnswerMetadataUtil.computeMajorIssueConfigs(table), equalTo(ImmutableMap.of())); }
@Test public void testAddValidRow() { TableAnswerElement table = new TableAnswerElement(twoKeyTableMetadata); Row row = Row.builder().put("key1", null).put("key2", null).build(); table.addRow(row); assertThat(table.getRows().getData(), contains(row)); }
@Test public void testComputeColumnMaxNoRows() { String columnName = "col"; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.INTEGER, "foobar")), new DisplayHints().getTextDesc())); assertThat(AnswerMetadataUtil.computeColumnMax(table, columnName, _logger), nullValue()); }
@Test public void testComputeColumnMaxNullInteger() { String columnName = "col"; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.INTEGER, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, null)); assertThat(AnswerMetadataUtil.computeColumnMax(table, columnName, _logger), nullValue()); }
@Test public void testComputeColumnMaxInvalidSchema() { String columnName = "col"; String value = "hello"; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.STRING, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, value)); assertThat(AnswerMetadataUtil.computeColumnMax(table, columnName, _logger), nullValue()); }