private static NodeIdentifierWithPredicates firstKeyOf(final YangInstanceIdentifier id, final Predicate<PathArgument> match) { final PathArgument ret = Iterables.find(id.getPathArguments(), match); Preconditions.checkArgument(ret instanceof NodeIdentifierWithPredicates, "Non-key peer identifier %s", ret); return (NodeIdentifierWithPredicates) ret; }
AdjInTracker(final DOMDataTreeChangeService service, final RIBSupportContextRegistry registry, final DOMTransactionChain chain, final YangInstanceIdentifier peerIId, @Nonnull final PerTableTypeRouteCounter effectiveRibInRouteCounters, @Nonnull final PerTableTypeRouteCounter adjRibInRouteCounters) { this.registry = Preconditions.checkNotNull(registry); this.chain = Preconditions.checkNotNull(chain); this.peerIId = Preconditions.checkNotNull(peerIId); this.effRibTables = this.peerIId.node(EffectiveRibIn.QNAME).node(Tables.QNAME); this.effectiveRibInRouteCounters = Preconditions.checkNotNull(effectiveRibInRouteCounters); this.adjRibInRouteCounters = Preconditions.checkNotNull(adjRibInRouteCounters); final DOMDataTreeIdentifier treeId = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, this.peerIId.node(AdjRibIn.QNAME).node(Tables.QNAME)); LOG.debug("Registered Effective RIB on {}", this.peerIId); this.reg = service.registerDataTreeChangeListener(treeId, this); }
/** * Returns a new InstanceIdentifier with only one path argument of type {@link NodeIdentifier} with supplied * QName. * * @param name QName of first node identifier * @return Instance Identifier with only one path argument of type {@link NodeIdentifier} */ public static YangInstanceIdentifier of(final QName name) { return create(new NodeIdentifier(name)); }
@Override boolean pathArgumentsEqual(final YangInstanceIdentifier other) { if (other instanceof StackedYangInstanceIdentifier) { final StackedYangInstanceIdentifier stacked = (StackedYangInstanceIdentifier) other; return pathArgument.equals(stacked.pathArgument) && parent.equals(stacked.parent); } return super.pathArgumentsEqual(other); }
/** * Returns new builder for InstanceIdentifier with path arguments copied from original instance identifier. * * @param origin InstanceIdentifier from which path arguments are copied. * @return new builder for InstanceIdentifier with path arguments copied from original instance identifier. */ public static InstanceIdentifierBuilder builder(final YangInstanceIdentifier origin) { return new YangInstanceIdentifierBuilder(origin.getPathArguments(), origin.hashCode()); }
private static YangInstanceIdentifier firstIdentifierOf(final YangInstanceIdentifier id, final Predicate<PathArgument> match) { final int idx = Iterables.indexOf(id.getPathArguments(), match); Preconditions.checkArgument(idx != -1, "Failed to find %s in %s", match, id); // we want the element at index idx to be included in the list return YangInstanceIdentifier.create(Iterables.limit(id.getPathArguments(), idx + 1)); }
private static YangInstanceIdentifier childYangId(@Nonnull final YangInstanceIdentifier topLevelIdentifier, @Nonnull final Map.Entry<YangInstanceIdentifier.PathArgument, DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> entry) { return YangInstanceIdentifier.builder(topLevelIdentifier) .node(entry.getKey()).build(); } }
private SchemaPath getSchemaPath(final YangInstanceIdentifier dataRoot) { return SchemaPath.create(Iterables.transform(dataRoot.getPathArguments(), PATH_ARG_TO_QNAME), dataRoot.equals(ROOT)); }
private static YangInstanceIdentifier.NodeIdentifierWithPredicates listNodeIdentifier(@Nonnull final YangInstanceIdentifier nodeIdentifier) { return java.util.Optional.ofNullable(nodeIdentifier.getLastPathArgument()) .filter(pathArgument -> pathArgument instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) .map(YangInstanceIdentifier.NodeIdentifierWithPredicates.class::cast) .orElseThrow(() -> new IllegalArgumentException( String.format("Unable to create list node identifier from %s", nodeIdentifier))); } }
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); }
private String getModuleName(final YangInstanceIdentifier path) { if (path.isEmpty()) { return UNKNOWN_MODULE_NAME; } String namespace = path.getPathArguments().iterator().next().getNodeType().getNamespace().toASCIIString(); String moduleName = configuration.getModuleNameFromNameSpace(namespace); return moduleName != null ? moduleName : UNKNOWN_MODULE_NAME; } }
public static String entityTypeFromEntityPath(YangInstanceIdentifier entityPath){ YangInstanceIdentifier parent = entityPath; while(!parent.isEmpty()) { if (EntityType.QNAME.equals(parent.getLastPathArgument().getNodeType())) { YangInstanceIdentifier.NodeIdentifierWithPredicates entityTypeLastPathArgument = (YangInstanceIdentifier.NodeIdentifierWithPredicates) parent.getLastPathArgument(); return (String) entityTypeLastPathArgument.getKeyValues().get(ENTITY_TYPE_QNAME); } parent = parent.getParent(); } return null; }
private void checkIdentifierReferencesData(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) { final PathArgument arg; if (!path.isEmpty()) { arg = path.getLastPathArgument(); checkArgument(arg != null, "Instance identifier %s has invalid null path argument", path); } else { arg = rootNode.getIdentifier(); } checkIdentifierReferencesData(arg, data); }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof DOMDataTreeIdentifier)) { return false; } DOMDataTreeIdentifier other = (DOMDataTreeIdentifier) obj; if (datastoreType != other.datastoreType) { return false; } return rootIdentifier.equals(other.rootIdentifier); }
/** * Subclasses of this class are required to implement creation of parent nodes based on behaviour of their * underlying transaction. * * @param store an instance of LogicalDatastoreType * @param domPath an instance of YangInstanceIdentifier * @param path an instance of InstanceIdentifier */ protected final void ensureParentsByMerge(final LogicalDatastoreType store, final YangInstanceIdentifier domPath, final InstanceIdentifier<?> path) { final YangInstanceIdentifier parentPath = domPath.getParent(); if (parentPath != null) { final NormalizedNode<?, ?> parentNode = getCodec().instanceIdentifierToNode(parentPath); getDelegate().merge(store, YangInstanceIdentifier.create(parentNode.getIdentifier()), parentNode); } }
private boolean isFilterPresent(final Optional<YangInstanceIdentifier> filterPath) { return filterPath.isPresent() && !filterPath.get().isEmpty(); }
@Override public final void exit(final int depth) { Preconditions.checkArgument(depth >= 0); YangInstanceIdentifier next = current; for (int i = 0; i < depth; ++i) { next = next.getParent(); Preconditions.checkState(next != null); } current = next; }
private static int calculateSize(final YangInstanceIdentifier parent) { YangInstanceIdentifier current = parent; for (int i = 1;; ++i) { final Collection<PathArgument> args = current.tryReversePathArguments(); if (args != null) { return i + args.size(); } verify(current instanceof StackedYangInstanceIdentifier); current = current.getParent(); } }