@Nonnull @VisibleForTesting static Row getAggregateRow( WarningTriplet triplet, Map<String, SortedSet<Integer>> filelines, Map<String, ColumnMetadata> columnMetadataMap) { return Row.builder(columnMetadataMap) .put( COL_FILELINES, filelines.entrySet().stream() .map(e -> new FileLines(e.getKey(), e.getValue())) .collect(ImmutableList.toImmutableList())) .put(COL_TEXT, triplet._text) .put(COL_PARSER_CONTEXT, triplet._parserContext) .put(COL_COMMENT, firstNonNull(triplet._comment, "(not provided)")) .build(); }
@Nonnull @VisibleForTesting static Row getRow( String filename, ParseStatus status, @Nullable Collection<String> hostsProduced) { Row.TypedRowBuilder builder = Row.builder(TABLE_METADATA.toColumnMap()); builder.put(COL_FILENAME, filename); builder.put(COL_PARSE_STATUS, status.toString()); ImmutableList.Builder<Node> nodesProduced = ImmutableList.builder(); for (String hostname : firstNonNull(hostsProduced, Collections.<String>emptyList())) { nodesProduced.add(new Node(hostname)); } builder.put(COL_NODES, nodesProduced.build()); return builder.build(); }
@VisibleForTesting // Entry is: filename -> struct type -> struct name -> defined structure info static List<Row> processEntryToRows( Entry<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> e) { List<Row> rows = new ArrayList<>(); String filename = e.getKey(); for (Entry<String, SortedMap<String, DefinedStructureInfo>> e1 : e.getValue().entrySet()) { String structType = e1.getKey(); for (Entry<String, DefinedStructureInfo> e2 : e1.getValue().entrySet()) { String name = e2.getKey(); DefinedStructureInfo info = e2.getValue(); if (info.getNumReferrers() == 0) { rows.add( Row.builder(COLUMN_METADATA_MAP) .put(COL_STRUCTURE_TYPE, structType) .put(COL_STRUCTURE_NAME, name) .put(COL_SOURCE_LINES, new FileLines(filename, info.getDefinitionLines())) .build()); } } } return rows; }
private static @Nonnull Row buildPassivePeerWithoutRemoteRow( Map<String, ColumnMetadata> metadataMap, BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, SessionStatus status) { return Row.builder(metadataMap) .put(COL_ESTABLISHED_STATUS, status) .put(COL_LOCAL_INTERFACE, null) .put(COL_LOCAL_AS, passivePeer.getLocalAs()) .put(COL_LOCAL_IP, passivePeer.getLocalIp()) .put(COL_NODE, new Node(passiveId.getHostname())) .put( COL_REMOTE_AS, new SelfDescribingObject(Schema.list(Schema.LONG), passivePeer.getRemoteAs())) .put(COL_REMOTE_NODE, null) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.PREFIX, passivePeer.getPeerPrefix())) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()) .build(); }
@Test public void testConfigToRow() { Mlag m = Mlag.builder() .setId("ID") .setPeerAddress(Ip.parse("1.1.1.1")) .setPeerInterface("Port-Channel1") .build(); final String hostname = "node"; Row r = configToRow(hostname, m); assertThat( r, equalTo( Row.builder(getMetadata().toColumnMap()) .put(COL_NODE, new Node(hostname)) .put(COL_MLAG_ID, m.getId()) .put(COL_MLAG_PEER_ADDRESS, m.getPeerAddress()) .put(COL_MLAG_PEER_INTERFACE, new NodeInterfacePair(hostname, "Port-Channel1")) .put(COL_MLAG_LOCAL_INTERFACE, null) .build())); }
@VisibleForTesting @Nonnull static Row configToRow(String hostname, Mlag mlag) { return Row.builder(getMetadata().toColumnMap()) .put(COL_NODE, new Node(hostname)) .put(COL_MLAG_ID, mlag.getId()) .put(COL_MLAG_PEER_ADDRESS, mlag.getPeerAddress()) .put( COL_MLAG_PEER_INTERFACE, mlag.getPeerInterface() != null ? new NodeInterfacePair(hostname, mlag.getPeerInterface()) : null) .put( COL_MLAG_LOCAL_INTERFACE, mlag.getLocalInterface() != null ? new NodeInterfacePair(hostname, mlag.getLocalInterface()) : null) .build(); }
private static @Nonnull Row buildPassivePeerWithoutRemoteRow( Map<String, ColumnMetadata> metadataMap, BgpPeerConfigId passiveId, BgpPassivePeerConfig passivePeer, ConfiguredSessionStatus status) { return Row.builder(metadataMap) .put(COL_CONFIGURED_STATUS, status) .put(COL_LOCAL_INTERFACE, null) .put(COL_LOCAL_AS, passivePeer.getLocalAs()) .put(COL_LOCAL_IP, passivePeer.getLocalIp()) .put(COL_NODE, new Node(passiveId.getHostname())) .put( COL_REMOTE_AS, new SelfDescribingObject(Schema.list(Schema.LONG), passivePeer.getRemoteAs())) .put(COL_REMOTE_NODE, null) .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.PREFIX, passivePeer.getPeerPrefix())) .put(COL_SESSION_TYPE, SessionType.UNSET) .put(COL_VRF, passiveId.getVrfName()) .build(); }
@Test public void testUndefinedReference() { IpAccessListLine aclLine = IpAccessListLine.accepting().setMatchCondition(new PermittedByAcl("???")).build(); _aclb.setLines(ImmutableList.of(aclLine)).setName("acl").build(); TableAnswerElement answer = answer(new FilterLineReachabilityQuestion()); // Construct the expected result. Should find an undefined ACL result. Multiset<Row> expected = ImmutableMultiset.of( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(_c1.getHostname() + ": acl")) .put(COL_UNREACHABLE_LINE, aclLine.toString()) .put(COL_UNREACHABLE_LINE_ACTION, PERMIT) .put(COL_BLOCKING_LINES, ImmutableList.of()) .put(COL_DIFF_ACTION, false) .put(COL_REASON, UNDEFINED_REFERENCE) .build()); assertThat(answer.getRows().getData(), equalTo(expected)); }
public void addCycle(String hostname, List<String> aclsInCycle) { _rows.add( Row.builder(COLUMN_METADATA) .put(COL_SOURCES, ImmutableList.of(hostname + ": " + String.join(", ", aclsInCycle))) .put(COL_UNREACHABLE_LINE, null) .put(COL_UNREACHABLE_LINE_ACTION, null) .put(COL_BLOCKING_LINES, null) .put(COL_DIFF_ACTION, null) .put(COL_REASON, Reason.CYCLICAL_REFERENCE) .put( COL_ADDITIONAL_INFO, String.format( "Cyclic references in node '%s': %s -> %s", hostname, String.join(" -> ", aclsInCycle), aclsInCycle.get(0))) .build()); }
@Test public void putListType() { TypedRowBuilder builder = Row.builder( ImmutableMap.of( "col", new ColumnMetadata("col", Schema.list(Schema.INTEGER), "desc"))); // we should be able to put a list but not a base type Row row = builder.put("col", ImmutableList.of(2)).build(); assertThat( row.get("col", Schema.list(Schema.INTEGER)), Matchers.equalTo(ImmutableList.of(2))); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage("Cannot convert"); builder.put("col", 2); }
@VisibleForTesting static Row createRow( Map<String, ColumnMetadata> columns, String node, Integer vlan, Map<Integer, Builder<NodeInterfacePair>> switchedVlanInterfaces, Map<Integer, Integer> vlanVnis) { return Row.builder(columns) .put(COL_NODE, new Node(node)) .put(COL_VLAN_ID, vlan) .put(COL_INTERFACES, switchedVlanInterfaces.get(vlan).build()) .put(COL_VXLAN_VNI, vlanVnis.get(vlan)) .build(); }
@Test public void putBaseType() { TypedRowBuilder builder = Row.builder(ImmutableMap.of("col", new ColumnMetadata("col", Schema.INTEGER, "desc"))); // we should be able to put an Integer but not a string Row row = builder.put("col", 2).build(); assertThat(row.get("col", Schema.INTEGER), Matchers.equalTo(2)); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage("Cannot convert"); builder.put("col", "string"); }
@Nonnull @VisibleForTesting static Row getRow(String node, ConvertStatus status) { Row.TypedRowBuilder builder = Row.builder(TABLE_METADATA.toColumnMap()); builder.put(COL_NODE, node); builder.put(COL_CONVERT_STATUS, status.toString()); return builder.build(); }
@Nonnull @VisibleForTesting static Row getRow(String nodeName, Warning warning) { return Row.builder(TABLE_METADATA.toColumnMap()) .put(COL_NODE, new Node(nodeName)) .put(COL_TYPE, ImmutableList.of(warning.getTag())) .put(COL_COMMENT, warning.getText()) .build(); }
private static Row toRow(DefinedStructureRow info) { return Row.builder(COLUMN_METADATA_MAP) .put(COL_STRUCTURE_NAME, info.getStructName()) .put(COL_STRUCT_TYPE, info.getStructType()) .put(COL_SOURCE_LINES, new FileLines(info.getFilename(), info.getDefinitionLines())) .build(); } }
@Test public void fillInEmptyColumnsOnBuild() { Row row = Row.builder(ImmutableMap.of("col", new ColumnMetadata("col", Schema.INTEGER, "desc"))) .build(); assertThat(row.getColumnNames(), contains("col")); assertThat(row.hasNonNull("col"), equalTo(false)); } }
@Test public void putNullValue() { TypedRowBuilder builder = Row.builder(ImmutableMap.of("col", new ColumnMetadata("col", Schema.INTEGER, "desc"))); // we should be able to put null Row row = builder.put("col", null).build(); assertThat(row.get("col", Schema.INTEGER), Matchers.is(nullValue())); }
@Nonnull @VisibleForTesting static Row getRow( String filename, ParseWarning warning, Map<String, ColumnMetadata> columnMetadataMap) { return Row.builder(columnMetadataMap) .put(COL_FILENAME, filename) .put(COL_LINE, warning.getLine()) .put(COL_TEXT, warning.getText()) .put(COL_PARSER_CONTEXT, warning.getParserContext()) .put(COL_COMMENT, firstNonNull(warning.getComment(), "(not provided)")) .build(); }
@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())); }
/** 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()); } } }