private boolean isFilterPresent(final Optional<YangInstanceIdentifier> filterPath) { return filterPath.isPresent() && !filterPath.get().isEmpty(); }
/** * Create an RPC identifier with a particular context reference. * * @param type RPC type, SchemaPath of its definition, may not be null * @param contextReference Context reference, null means a global RPC identifier. * @return A global RPC identifier, guaranteed to be non-null. */ public static @Nonnull DOMRpcIdentifier create(final @Nonnull SchemaPath type, final @Nullable YangInstanceIdentifier contextReference) { if (contextReference == null || contextReference.isEmpty()) { return new Global(type); } return new Local(type, contextReference); }
@Override public final void exit() { Preconditions.checkState(!current.isEmpty()); current = Verify.verifyNotNull(current.getParent()); }
private Iterable<PathArgument> stripShardPath(final YangInstanceIdentifier listenerPath) { if (shardPath.isEmpty()) { return listenerPath.getPathArguments(); } final List<PathArgument> listenerPathArgs = new ArrayList<>(listenerPath.getPathArguments()); final Iterator<PathArgument> shardIter = shardPath.getPathArguments().iterator(); final Iterator<PathArgument> listenerIter = listenerPathArgs.iterator(); while (shardIter.hasNext()) { if (shardIter.next().equals(listenerIter.next())) { listenerIter.remove(); } else { break; } } return listenerPathArgs; }
@Override public final void exit() { Preconditions.checkState(!current.isEmpty()); current = Verify.verifyNotNull(current.getParent()); }
/** * Create an RPC identifier with a particular context reference. * * @param type RPC type, SchemaPath of its definition, may not be null * @param contextReference Context reference, null means a global RPC identifier. * @return A global RPC identifier, guaranteed to be non-null. */ public static DOMRpcIdentifier create(final SchemaPath type, final @Nullable YangInstanceIdentifier contextReference) { if (contextReference == null || contextReference.isEmpty()) { return new Global(type); } return new Local(type, contextReference); }
Optional<NormalizedNodeContext> findDescendant(final YangInstanceIdentifier path) { if (path.isEmpty()) { return Optional.of(this); } NormalizedNodeContext ctxWalk = this; NormalizedNode<?, ?> dataWalk = node; for (PathArgument arg : path.getPathArguments()) { checkArgument(dataWalk instanceof DataContainerNode, "Path %s refers beyond node %s", path, dataWalk); final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> optChild = ((DataContainerNode)dataWalk).getChild(arg); if (!optChild.isPresent()) { return Optional.empty(); } dataWalk = optChild.get(); ctxWalk = createChild(dataWalk); } return Optional.of(ctxWalk.createChild(dataWalk)); }
Optional<NormalizedNodeContext> findDescendant(final YangInstanceIdentifier path) { if (path.isEmpty()) { return Optional.of(this); } NormalizedNodeContext ctxWalk = this; NormalizedNode<?, ?> dataWalk = node; for (PathArgument arg : path.getPathArguments()) { checkArgument(dataWalk instanceof DataContainerNode, "Path %s refers beyond node %s", path, dataWalk); final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> optChild = ((DataContainerNode)dataWalk).getChild(arg); if (!optChild.isPresent()) { return Optional.empty(); } dataWalk = optChild.get(); ctxWalk = createChild(dataWalk); } return Optional.of(ctxWalk.createChild(dataWalk)); }
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); }
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; } }
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 Set<String> getGlobalRpc() { RoutingTable table = getLocalData(); Set<String> globalRpc = new HashSet<>(table.getRoutes().size()); for (DOMRpcIdentifier route : table.getRoutes()) { if (route.getContextReference().isEmpty()) { globalRpc.add(route.getType().toString()); } } log.debug("Locally registered global RPCs {}", globalRpc); return globalRpc; }
@Override public Set<String> getLocalRegisteredRoutedRpc() { RoutingTable table = getLocalData(); Set<String> routedRpc = new HashSet<>(table.getRoutes().size()); for (DOMRpcIdentifier route : table.getRoutes()) { if (!route.getContextReference().isEmpty()) { routedRpc.add(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + route.getType()); } } log.debug("Locally registered routed RPCs {}", routedRpc); return routedRpc; }
/** * Search if the routing table route type contains name. */ private static Map<String, String> getRpcMemberMapByName(final RoutingTable table, final String name, final String address) { Set<DOMRpcIdentifier> routes = table.getRoutes(); Map<String, String> rpcMap = new HashMap<>(routes.size()); for (DOMRpcIdentifier route : routes) { if (!route.getContextReference().isEmpty()) { String type = route.getType().toString(); if (type.contains(name)) { rpcMap.put(ROUTE_CONSTANT + route.getContextReference() + NAME_CONSTANT + type, address); } } } return rpcMap; }
/** * Search if the routing table route String contains routeName. */ private static Map<String,String> getRpcMemberMapByRoute(final RoutingTable table, final String routeName, final String address) { Set<DOMRpcIdentifier> routes = table.getRoutes(); Map<String, String> rpcMap = new HashMap<>(routes.size()); for (DOMRpcIdentifier route : routes) { if (!route.getContextReference().isEmpty()) { String routeString = route.getContextReference().toString(); if (routeString.contains(routeName)) { rpcMap.put(ROUTE_CONSTANT + routeString + NAME_CONSTANT + route.getType(), address); } } } return rpcMap; }
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 static NormalizedNode<?, ?> createRoot(final YangInstanceIdentifier path) { if (path.isEmpty()) { return ROOT_CONTAINER; } final PathArgument arg = path.getLastPathArgument(); if (arg instanceof NodeIdentifier) { return ImmutableContainerNodeBuilder.create().withNodeIdentifier((NodeIdentifier) arg).build(); } if (arg instanceof NodeIdentifierWithPredicates) { return ImmutableNodes.mapEntryBuilder().withNodeIdentifier((NodeIdentifierWithPredicates) arg).build(); } // FIXME: implement augmentations and leaf-lists throw new IllegalArgumentException("Unsupported root node " + arg); } }
private static void applyToCursorAwareModification(final CursorAwareDataTreeModification modification, final DataTreeCandidate candidate) { final YangInstanceIdentifier candidatePath = candidate.getRootPath(); if (candidatePath.isEmpty()) { try (DataTreeModificationCursor cursor = modification.openCursor()) { DataTreeCandidateNodes.applyRootToCursor(cursor, candidate.getRootNode()); } } else { try (DataTreeModificationCursor cursor = modification.openCursor(candidatePath.getParent()).get()) { DataTreeCandidateNodes.applyRootedNodeToCursor(cursor, candidatePath, candidate.getRootNode()); } } }
private static NormalizedNode<?, ?> createRoot(final YangInstanceIdentifier path) { if (path.isEmpty()) { return ROOT_CONTAINER; } final PathArgument arg = path.getLastPathArgument(); if (arg instanceof NodeIdentifier) { return ImmutableContainerNodeBuilder.create().withNodeIdentifier((NodeIdentifier) arg).build(); } if (arg instanceof NodeIdentifierWithPredicates) { return ImmutableNodes.mapEntryBuilder().withNodeIdentifier((NodeIdentifierWithPredicates) arg).build(); } // FIXME: implement augmentations and leaf-lists throw new IllegalArgumentException("Unsupported root node " + arg); } }
private static void applyToCursorAwareModification(final CursorAwareDataTreeModification modification, final DataTreeCandidate candidate) { final YangInstanceIdentifier candidatePath = candidate.getRootPath(); if (candidatePath.isEmpty()) { try (DataTreeModificationCursor cursor = modification.openCursor()) { DataTreeCandidateNodes.applyRootToCursor(cursor, candidate.getRootNode()); } } else { try (DataTreeModificationCursor cursor = modification.openCursor(candidatePath.getParent()).get()) { DataTreeCandidateNodes.applyRootedNodeToCursor(cursor, candidatePath, candidate.getRootNode()); } } }