private NodeIdentifierWithPredicates transform(final NodeIdentifierWithPredicates identifier) { Map<QName, Object> keyValues = new HashMap<>(); for (Map.Entry<QName, Object> original : identifier.getKeyValues().entrySet()) { keyValues.put(transform(original.getKey()), original.getValue()); } return new NodeIdentifierWithPredicates(transform(identifier.getNodeType()), keyValues); } }
private static CharSequence convertListToRestconfIdentifier( final YangInstanceIdentifier.NodeIdentifierWithPredicates argument, final ListSchemaNode node, final SchemaContext schemaContext) { QName _nodeType = argument.getNodeType(); final CharSequence nodeIdentifier = toRestconfIdentifier(_nodeType, schemaContext); final Map<QName, Object> keyValues = argument.getKeyValues(); StringBuilder sb = new StringBuilder(); sb.append('/'); sb.append(nodeIdentifier); sb.append('/'); List<QName> keyDefinition = node.getKeyDefinition(); boolean _hasElements = false; for (final QName key : keyDefinition) { if (_hasElements) { sb.append('/'); } else { _hasElements = true; } Object _get = keyValues.get(key); sb.append(toUriString(_get)); } return sb.toString(); }
private CharSequence convertToRestconfIdentifierWithPredicates(final NodeIdentifierWithPredicates argument, final ListSchemaNode node, final DOMMountPoint mount) { final QName nodeType = argument.getNodeType(); final CharSequence nodeIdentifier = this.toRestconfIdentifier(nodeType, mount); final Map<QName, Object> keyValues = argument.getKeyValues();
writeQName(nodeIdentifierWithPredicates.getNodeType());
/** * Create new table instance * * @param tableTypes * @param yangTableRootIId * @param tx * @param registry * @return */ private ImmutableMap.Builder<TablesKey, TableContext> createTableInstance(final Set<TablesKey> tableTypes, final YangInstanceIdentifier yangTableRootIId, final DOMDataWriteTransaction tx, final RIBExtensionConsumerContext ribExtensions, final BindingCodecTree tree) { final ImmutableMap.Builder<TablesKey, TableContext> tb = ImmutableMap.builder(); for (final TablesKey k : tableTypes) { final RIBSupport rs = ribExtensions.getRIBSupport(k); if (rs == null) { LOG.warn("No support for table type {}, skipping it", k); continue; } final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(yangTableRootIId); final NodeIdentifierWithPredicates key = TablesUtil.toYangTablesKey(k); idb.nodeWithKey(key.getNodeType(), key.getKeyValues()); final TableContext ctx = new TableContext(rs, idb.build(), tree); ctx.createTable(tx); tx.put(LogicalDatastoreType.OPERATIONAL, ctx.getTableId().node(BMP_ATTRIBUTES_QNAME).node(ATTRIBUTES_UPTODATE_FALSE.getNodeType()), ATTRIBUTES_UPTODATE_FALSE); LOG.debug("Created table instance {}", ctx.getTableId()); tb.put(k, ctx); } return tb; }
@Override public void writePathArgument(final PathArgument pathArgument) throws IOException { byte type = PathArgumentTypes.getSerializablePathArgumentType(pathArgument); output.writeByte(type); switch(type) { case PathArgumentTypes.NODE_IDENTIFIER: NodeIdentifier nodeIdentifier = (NodeIdentifier) pathArgument; writeQName(nodeIdentifier.getNodeType()); break; case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES: NodeIdentifierWithPredicates nodeIdentifierWithPredicates = (NodeIdentifierWithPredicates) pathArgument; writeQName(nodeIdentifierWithPredicates.getNodeType()); writeKeyValueMap(nodeIdentifierWithPredicates.getKeyValues()); break; case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE : NodeWithValue<?> nodeWithValue = (NodeWithValue<?>) pathArgument; writeQName(nodeWithValue.getNodeType()); writeObject(nodeWithValue.getValue()); break; case PathArgumentTypes.AUGMENTATION_IDENTIFIER : AugmentationIdentifier augmentationIdentifier = (AugmentationIdentifier) pathArgument; // No Qname in augmentation identifier writeQNameSet(augmentationIdentifier.getPossibleChildNames()); break; default : throw new IllegalStateException("Unknown node identifier type is found : " + pathArgument.getClass().toString() ); } }
private void startLocRib(final TablesKey key, final PolicyDatabase pd) { LOG.debug("Creating LocRib table for {}", key); // create locRibWriter for each table final DOMDataWriteTransaction tx = this.domChain.newWriteOnlyTransaction(); final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> table = ImmutableNodes.mapEntryBuilder(); table.withNodeIdentifier(RibSupportUtils.toYangTablesKey(key)); table.withChild(EMPTY_TABLE_ATTRIBUTES); final NodeIdentifierWithPredicates tableKey = RibSupportUtils.toYangTablesKey(key); final InstanceIdentifierBuilder tableId = YangInstanceIdentifier.builder(this.yangRibId.node(LocRib.QNAME).node(Tables.QNAME)); tableId.nodeWithKey(tableKey.getNodeType(), tableKey.getKeyValues()); for (final Entry<QName, Object> e : tableKey.getKeyValues().entrySet()) { table.withChild(ImmutableNodes.leafNode(e.getKey(), e.getValue())); } final ChoiceNode routes = this.ribContextRegistry.getRIBSupportContext(key).getRibSupport().emptyRoutes(); table.withChild(routes); tx.put(LogicalDatastoreType.OPERATIONAL, tableId.build(), table.build()); try { tx.submit().checkedGet(); } catch (final TransactionCommitFailedException e1) { LOG.error("Failed to initiate LocRIB for key {}", key, e1); } PathSelectionMode pathSelectionStrategy = this.bestPathSelectionStrategies.get(key); if (pathSelectionStrategy == null) { pathSelectionStrategy = BasePathSelectionModeFactory.createBestPathSelectionStrategy(); } this.locRibs.add(LocRibWriter.create(this.ribContextRegistry, key, createPeerChain(this), getYangRibId(), this.localAs, getService(), pd, this.cacheDisconnectedPeers, pathSelectionStrategy, this.renderStats.getLocRibRouteCounter().init(key))); }
private static String toString(NodeIdentifierWithPredicates pathArgument){ return pathArgument.getNodeType().toString() + '[' + pathArgument.getKeyValues() + ']'; }
private void installAdjRibInTables(final YangInstanceIdentifier newPeerPath, final TablesKey tableKey, final RIBSupportContext rs, final NodeIdentifierWithPredicates instanceIdentifierKey, final DOMDataWriteTransaction tx, final Builder<TablesKey, TableContext> tb) { // We will use table keys very often, make sure they are optimized final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(newPeerPath.node(EMPTY_ADJRIBIN.getIdentifier()).node(TABLES)); idb.nodeWithKey(instanceIdentifierKey.getNodeType(), instanceIdentifierKey.getKeyValues()); final TableContext ctx = new TableContext(rs, idb.build()); ctx.createEmptyTableStructure(tx); tx.merge(LogicalDatastoreType.OPERATIONAL, ctx.getTableId().node(Attributes.QNAME).node(ATTRIBUTES_UPTODATE_FALSE.getNodeType()), ATTRIBUTES_UPTODATE_FALSE); LOG.debug("Created table instance {}", ctx.getTableId()); tb.put(tableKey, ctx); }
@Override public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint) throws IOException, IllegalArgumentException { Preconditions.checkNotNull(identifier, "Node identifier should not be null"); LOG.debug("Starting a new map entry node"); startNode(identifier.getNodeType(), NodeTypes.MAP_ENTRY_NODE); writeKeyValueMap(identifier.getKeyValues()); }
@Override public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint) throws IOException, IllegalArgumentException { Preconditions.checkNotNull(identifier, "Node identifier should not be null"); LOG.trace("Starting a new map entry node"); startNode(identifier.getNodeType(), NodeTypes.MAP_ENTRY_NODE); writeKeyValueMap(identifier.getKeyValues()); }