@JsonCreator private static TableMetadata jsonCreator( @Nullable @JsonProperty(PROP_COLUMN_METADATA) List<ColumnMetadata> columnMetadata, @Nullable @JsonProperty(PROP_DISPLAY_HINTS) DisplayHints displayHints, @Nullable @JsonProperty(PROP_TEXT_DESC) String textDesc) { return new TableMetadata( columnMetadata, textDesc == null && displayHints != null ? displayHints.getTextDesc() : textDesc); }
/** Create table metadata for this answer. */ private static TableMetadata getTableMetadata() { List<ColumnMetadata> columnMetadata = getColumnMetadata(); return new TableMetadata( columnMetadata, String.format( "On node ${%s} in VRF ${%s}, interface ${%s} has IP ${%s}.", COL_NODE, COL_VRFNAME, COL_INTERFACE_NAME, COL_IP)); }
/** Create metadata for the new traceroute v2 answer */ public static TableMetadata metadata() { List<ColumnMetadata> columnMetadata = ImmutableList.of( new ColumnMetadata(COL_FORWARD_FLOW, Schema.FLOW, "The forward flow.", true, false), new ColumnMetadata(COL_FORWARD_TRACE, Schema.TRACE, "The forward trace.", false, true), new ColumnMetadata(COL_REVERSE_FLOW, Schema.FLOW, "The reverse flow.", false, true), new ColumnMetadata(COL_REVERSE_TRACE, Schema.TRACE, "The reverse trace.", false, true)); return new TableMetadata( columnMetadata, String.format("Bidirectional paths for flow ${%s}", COL_FORWARD_FLOW)); }
@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; }
public static TableMetadata createMetadata(Question question) { String textDesc = DEFAULT_TEXT_DESC; DisplayHints dhints = question.getDisplayHints(); if (dhints != null && dhints.getTextDesc() != null) { textDesc = dhints.getTextDesc(); } return new TableMetadata(COLUMN_METADATA, textDesc); } }
public static TableMetadata createMetadata(Question question) { String textDesc = DEFAULT_TEXT_DESC; DisplayHints dhints = question.getDisplayHints(); if (dhints != null && dhints.getTextDesc() != null) { textDesc = dhints.getTextDesc(); } return new TableMetadata(COLUMN_METADATA, textDesc); }
static TableMetadata createTableMetadata(@Nonnull NodePropertiesQuestion question) { String textDesc = String.format("Properties of node ${%s}.", COL_NODE); DisplayHints dhints = question.getDisplayHints(); if (dhints != null && dhints.getTextDesc() != null) { textDesc = dhints.getTextDesc(); } return new TableMetadata(createColumnMetadata(question.getProperties()), textDesc); }
/** Creates a {@link TableMetadata} object from the question. */ static TableMetadata createTableMetadata(BgpProcessConfigurationQuestion question) { String textDesc = String.format( "Properties of BGP process ${%s}:${%s}:${%s}.", COL_NODE, COL_VRF, COL_ROUTER_ID); DisplayHints dhints = question.getDisplayHints(); if (dhints != null && dhints.getTextDesc() != null) { textDesc = dhints.getTextDesc(); } return new TableMetadata(createColumnMetadata(question.getProperties()), textDesc); }
static TableMetadata getTableMetadata() { List<ColumnMetadata> columnMetadata = ImmutableList.of( new ColumnMetadata(COL_NODE, Schema.NODE, "The node where action takes place"), new ColumnMetadata(COL_VRF, Schema.STRING, "The VRF where action takes place"), new ColumnMetadata( COL_PEER, Schema.NODE, "The node's neighbor to which the action applies"), new ColumnMetadata(COL_ACTION, Schema.STRING, "The action that takes place"), new ColumnMetadata(COL_PREFIX, Schema.PREFIX, "The prefix in question")); return new TableMetadata(columnMetadata, TEXT_DESC); }
/** Creates a {@link TableMetadata} object from the question. */ static TableMetadata createTableMetadata(OspfPropertiesQuestion question) { String textDesc = String.format( "Properties of OSPF process ${%s}:${%s}:${%s}.", COL_NODE, COL_VRF, COL_PROCESS_ID); DisplayHints dhints = question.getDisplayHints(); if (dhints != null && dhints.getTextDesc() != null) { textDesc = dhints.getTextDesc(); } return new TableMetadata(createColumnMetadata(question.getProperties()), textDesc); }
/** Creates a {@link TableMetadata} object from the question. */ static TableMetadata createTableMetadata(BgpPeerConfigurationQuestion question) { String textDesc = String.format( "Properties of BGP peer ${%s}:${%s}: ${%s}", COL_NODE, COL_VRF, COL_REMOTE_IP); DisplayHints dhints = question.getDisplayHints(); if (dhints != null && dhints.getTextDesc() != null) { textDesc = dhints.getTextDesc(); } return new TableMetadata(createColumnMetadata(question.getProperties()), textDesc); }
private @Nonnull Multiset<Row> getRows(String property) { InterfacePropertySpecifier propertySpecifier = new InterfacePropertySpecifier(property); return InterfacePropertiesAnswerer.getProperties( propertySpecifier, ImmutableMap.of(HOSTNAME, _c), ImmutableSet.of(HOSTNAME), new InterfacesSpecifier(INTERFACE_NAME), new TableMetadata( InterfacePropertiesAnswerer.createColumnMetadata(propertySpecifier), (String) null) .toColumnMap()); }
@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 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 constructorDuplicateColumnNames() { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata("col1", Schema.STRING, "desc"), new ColumnMetadata("col2", Schema.STRING, "desc"), new ColumnMetadata("col1", Schema.STRING, "desc")); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage("Cannot have two columns with the same name"); new TableMetadata(columns, "desc"); } }
@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()); }
@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 testComputeColumnMaxOneRowInteger() { String columnName = "col"; int value = 5; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.INTEGER, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, value)); assertThat(AnswerMetadataUtil.computeColumnMax(table, columnName, _logger), equalTo(value)); }
@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 testComputeColumnMaxOneRowIssue() { String columnName = "col"; int severity = 5; Issue value = new Issue("blah", severity, new Issue.Type("1", "2")); TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.ISSUE, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, value)); assertThat(AnswerMetadataUtil.computeColumnMax(table, columnName, _logger), equalTo(severity)); }