/** * Creates {@link ColumnMetadata}s that the answer should have based on the {@code * propertySpecifier}. * * @param propertySpecifier The {@link NodePropertySpecifier} that describes the set of properties * @return The {@link List} of {@link ColumnMetadata}s */ public static List<ColumnMetadata> createColumnMetadata(NodePropertySpecifier propertySpecifier) { return new ImmutableList.Builder<ColumnMetadata>() .add(new ColumnMetadata(COL_NODE, Schema.NODE, "Node", true, false)) .addAll( propertySpecifier.getMatchingProperties().stream() .map( prop -> new ColumnMetadata( getColumnName(prop), NodePropertySpecifier.JAVA_MAP.get(prop).getSchema(), "Property " + prop, false, true)) .collect(Collectors.toList())) .build(); }
/** * Creates {@link ColumnMetadata}s that the answer should have based on the {@code * propertySpecifier}. * * @param propertySpecifier The {@link InterfacePropertySpecifier} that describes the set of * properties * @return The {@link List} of {@link ColumnMetadata}s */ public static List<ColumnMetadata> createColumnMetadata( InterfacePropertySpecifier propertySpecifier) { return ImmutableList.<ColumnMetadata>builder() .add(new ColumnMetadata(COL_INTERFACE, Schema.INTERFACE, "Interface", true, false)) .addAll( propertySpecifier.getMatchingProperties().stream() .map( prop -> new ColumnMetadata( getColumnName(prop), InterfacePropertySpecifier.JAVA_MAP.get(prop).getSchema(), "Property " + prop, false, true)) .collect(Collectors.toList())) .build(); }
/** * Creates {@link ColumnMetadata}s that the answer should have based on the {@code * propertySpecifier}. * * @param propertySpecifier The {@link VxlanVniPropertySpecifier} that describes the set of * properties * @return The {@link List} of {@link ColumnMetadata}s */ public static List<ColumnMetadata> createColumnMetadata( VxlanVniPropertySpecifier propertySpecifier) { return ImmutableList.<ColumnMetadata>builder() .add(new ColumnMetadata(COL_NODE, Schema.STRING, "Node", true, false)) .add(new ColumnMetadata(COL_VNI, Schema.INTEGER, "VXLAN Segment ID", true, false)) .addAll( propertySpecifier.getMatchingProperties().stream() .map( prop -> new ColumnMetadata( prop, VxlanVniPropertySpecifier.JAVA_MAP.get(prop).getSchema(), "Property " + prop, false, true)) .collect(Collectors.toList())) .build(); }
"Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for VXLAN VNI settings '%s': %s", propertyDescriptor.getGetter().apply(vxlanVniProperties), propertyDescriptor.getSchema(), property, vxlanVniProperties,
"Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for BGP process '%s->%s-%s': %s", propertyDescriptor.getGetter().apply(bgpProcess), propertyDescriptor.getSchema(), property, nodeName,
"Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for OSPF process '%s->%s-%s': %s", propertyDescriptor.getGetter().apply(ospfProcess), propertyDescriptor.getSchema(), property, nodeName,
"Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for interface '%s': %s", propertyDescriptor.getGetter().apply(iface), propertyDescriptor.getSchema(), property, iface,
new ColumnMetadata( getColumnName(prop), BgpPeerPropertySpecifier.JAVA_MAP.get(prop).getSchema(), "Property " + prop, false,
"Type mismatch between property value ('%s') and Schema ('%s') for property '%s' for BGP peer '%s->%s-%s': %s", propertyDescriptor.getGetter().apply(peer), propertyDescriptor.getSchema(), property, node.getName(),
/** * Creates {@link ColumnMetadata}s that the answer should have based on the {@code * propertySpecifier}. * * @param propertySpecifier {@link BgpProcessPropertySpecifier} that describes the set of * properties * @return The {@link List} of {@link ColumnMetadata}s */ public static List<ColumnMetadata> createColumnMetadata( BgpProcessPropertySpecifier propertySpecifier) { return ImmutableList.<ColumnMetadata>builder() .add(new ColumnMetadata(COL_NODE, Schema.NODE, "Node", true, false)) .add(new ColumnMetadata(COL_VRF, Schema.STRING, "VRF", true, false)) .add(new ColumnMetadata(COL_ROUTER_ID, Schema.IP, "Router ID", true, false)) .addAll( propertySpecifier.getMatchingProperties().stream() .map( prop -> new ColumnMetadata( getColumnName(prop), BgpProcessPropertySpecifier.JAVA_MAP.get(prop).getSchema(), "Property " + prop, false, true)) .collect(Collectors.toList())) .build(); }
/** * Creates {@link ColumnMetadata}s that the answer should have based on the {@code * propertySpecifier}. * * @param propertySpecifier The {@link OspfPropertySpecifier} that describes the set of properties * @return The {@link List} of {@link ColumnMetadata}s */ public static List<ColumnMetadata> createColumnMetadata(OspfPropertySpecifier propertySpecifier) { return ImmutableList.<ColumnMetadata>builder() .add(new ColumnMetadata(COL_NODE, Schema.NODE, "Node", true, false)) .add(new ColumnMetadata(COL_VRF, Schema.STRING, "VRF", true, false)) .add(new ColumnMetadata(COL_PROCESS_ID, Schema.STRING, "Process ID", true, false)) .addAll( propertySpecifier.getMatchingProperties().stream() .map( prop -> new ColumnMetadata( getColumnName(prop), OspfPropertySpecifier.JAVA_MAP.get(prop).getSchema(), "Property " + prop, false, true)) .collect(Collectors.toList())) .build(); }
/** * Uses {@code propertyDescriptor} to extract the property value from {@code object} and insert * into {@code row} at {@code columnName}. * * @throws ClassCastException if the recovered property value is not compatible with the specified * {@link Schema} in the {@code propertyDescriptor}. */ public static <T> void fillProperty( PropertyDescriptor<T> propertyDescriptor, T object, String columnName, RowBuilder row) { checkArgument(propertyDescriptor != null, "'propertyDescriptor' cannot be null"); checkArgument(object != null, "'object' cannot be null"); checkArgument(columnName != null, "'columnName' cannot be null"); checkArgument(row != null, "'row' cannot be null"); Object propertyValue = propertyDescriptor.getGetter().apply(object); propertyValue = PropertySpecifier.convertTypeIfNeeded(propertyValue, propertyDescriptor.getSchema()); fillProperty(columnName, propertyValue, row, propertyDescriptor); // separate for testing }
/** Returns what is actually inserted into the answer */ static SelfDescribingObject insertedObject(Object obj, String structType) { Schema targetSchema = NamedStructureSpecifier.JAVA_MAP.get(structType).getSchema(); return new SelfDescribingObject( targetSchema, PropertySpecifier.convertTypeIfNeeded(obj, targetSchema)); } }
@VisibleForTesting static void fillProperty( String columnName, Object propertyValue, RowBuilder row, PropertyDescriptor<?> propertyDescriptor) { row.put(columnName, propertyValue); // if this barfs, the value cannot be converted to expected Schema row.build().get(columnName, propertyDescriptor.getSchema()); }