public NetconfDeviceRpc(final SchemaContext schemaContext, final RemoteDeviceCommunicator<NetconfMessage> listener, final MessageTransformer<NetconfMessage> transformer) { this.listener = listener; this.transformer = transformer; availableRpcs = Collections2.transform(schemaContext.getOperations(), RPC_TO_RPC_IDENTIFIER); }
private static RpcDefinition findCreateSubscriptionRpc() { return Iterables.getFirst(Collections2.filter(NOTIFICATIONS_SCHEMA_CTX.getOperations(), new Predicate<RpcDefinition>() { @Override public boolean apply(final RpcDefinition input) { return input.getQName().getLocalName().equals(CreateSubscription.CREATE_SUBSCRIPTION); } }), null); }
@Override public Set<RpcDefinition> getOperations() { return getCurrentSchema().getOperations(); }
private Optional<SchemaNode> tryFindRpc(final SchemaContext ctx, final QName qname) { return Optional.<SchemaNode>fromNullable(Iterables.find(ctx.getOperations(), new SchemaNodePredicate(qname), null)); }
@Override public void onGlobalContextUpdated(SchemaContext schemaContext) { if (schemaContext != null) { final Collection<RpcDefinition> defs = schemaContext.getOperations(); final Map<QName, RpcDefinition> newMap = new HashMap<>(defs.size()); for (final RpcDefinition operation : defs) { newMap.put(operation.getQName(), operation); } // FIXME: still not completely atomic qnameToRpc.set(ImmutableMap.copyOf(newMap)); setGlobalSchema(schemaContext); } }
@Override public void onGlobalContextUpdated(final SchemaContext context) { if (context != null) { final Collection<RpcDefinition> defs = context.getOperations(); final Map<QName, RpcDefinition> newMap = new HashMap<>(defs.size()); for (final RpcDefinition operation : defs) { newMap.put(operation.getQName(), operation); } // FIXME: still not completely atomic qnameToRpc.set(ImmutableMap.copyOf(newMap)); setGlobalSchema(context); } }
/** * Add all the locally registered RPCs in the clustered routing table */ private void announceSupportedRpcs(){ LOG.debug("Adding all supported rpcs to routing table"); final Set<RpcDefinition> currentlySupportedRpc = schemaContext.getOperations(); final List<DOMRpcIdentifier> rpcs = new ArrayList<>(); for (final RpcDefinition rpcDef : currentlySupportedRpc) { rpcs.add(DOMRpcIdentifier.create(rpcDef.getPath())); } if(!rpcs.isEmpty()) { rpcListener.onRpcAvailable(rpcs); } }
public NetconfMessageTransformer(final SchemaContext schemaContext, final boolean strictParsing) { this.counter = new MessageCounter(); this.schemaContext = schemaContext; parserFactory = DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, schemaContext, strictParsing); mappedRpcs = Maps.uniqueIndex(schemaContext.getOperations(), QNAME_FUNCTION); mappedNotifications = Multimaps.index(schemaContext.getNotifications(), QNAME_NOREV_FUNCTION); }
/** * Returns operation Input or Output Data container from operation definition. * * @param schema * - SchemaContext in which lookup should be performed * @param path * - Schema path of operation input/output data container * @return operation schema or null, if operation is not present in schema context. */ private ContainerSchemaNode getOperationDataSchema(final SchemaContext schema, final SchemaPath path) { Preconditions.checkNotNull(schema, "Schema context must not be null."); Preconditions.checkNotNull(path, "Schema path must not be null."); final Iterator<QName> it = path.getPathFromRoot().iterator(); Preconditions.checkArgument(it.hasNext(), "Operation must have QName."); final QName operationName = it.next(); Preconditions.checkArgument(it.hasNext(), "input or output must be part of path."); final QName inOrOut = it.next(); ContainerSchemaNode contSchemaNode = null; if ((contSchemaNode = getOperationDataSchema(schema.getOperations(), operationName, inOrOut)) == null) { contSchemaNode = getOperationDataSchema(schema.getActions(), operationName, inOrOut); } return contSchemaNode; }
/** * Returns RPC Input or Output Data container from RPC definition. * * @param schema SchemaContext in which lookup should be performed. * @param path Schema path of RPC input/output data container * @return Notification schema or null, if notification is not present in schema context. */ @Beta public static @Nullable ContainerSchemaNode getRpcDataSchema(final @NonNull SchemaContext schema, final @NonNull SchemaPath path) { requireNonNull(schema, "Schema context must not be null."); requireNonNull(path, "Schema path must not be null."); final Iterator<QName> it = path.getPathFromRoot().iterator(); checkArgument(it.hasNext(), "Rpc must have QName."); final QName rpcName = it.next(); checkArgument(it.hasNext(), "input or output must be part of path."); final QName inOrOut = it.next(); for (final RpcDefinition potential : schema.getOperations()) { if (rpcName.equals(potential.getQName())) { return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut); } } return null; }
private static Optional<DataNodeContainer> findFirstDataNodeContainerInRpcOrAction(final SchemaContext ctx, final Class<? extends TreeNode> targetType) { final YangModuleInfo moduleInfo; try { moduleInfo = BindingReflections.getModuleInfo(targetType); } catch (final Exception e) { throw new IllegalArgumentException( String.format("Failed to load module information for class %s", targetType), e); } Optional<DataNodeContainer> optional = null; optional = findFirst(ctx.getOperations(), moduleInfo, targetType); if (optional.isPresent()) { return optional; } else { return findFirst(ctx.getActions(), moduleInfo, targetType); } }
/** * Returns RPC Input or Output Data container from RPC definition. * * @param schema SchemaContext in which lookup should be performed. * @param path Schema path of RPC input/output data container * @return Notification schema or null, if notification is not present in schema context. */ @Beta public static @Nullable ContainerSchemaNode getRpcDataSchema(final @NonNull SchemaContext schema, final @NonNull SchemaPath path) { requireNonNull(schema, "Schema context must not be null."); requireNonNull(path, "Schema path must not be null."); final Iterator<QName> it = path.getPathFromRoot().iterator(); checkArgument(it.hasNext(), "Rpc must have QName."); final QName rpcName = it.next(); checkArgument(it.hasNext(), "input or output must be part of path."); final QName inOrOut = it.next(); for (final RpcDefinition potential : schema.getOperations()) { if (rpcName.equals(potential.getQName())) { return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut); } } return null; }
private static Optional<DataNodeContainer> findFirstDataNodeContainerInRpc(final SchemaContext ctx, final Class<? extends DataObject> targetType) { final YangModuleInfo moduleInfo; try { moduleInfo = BindingReflections.getModuleInfo(targetType); } catch (Exception e) { throw new IllegalArgumentException( String.format("Failed to load module information for class %s", targetType), e); } for(RpcDefinition rpc : ctx.getOperations()) { String rpcNamespace = rpc.getQName().getNamespace().toString(); String rpcRevision = rpc.getQName().getFormattedRevision(); if(moduleInfo.getNamespace().equals(rpcNamespace) && moduleInfo.getRevision().equals(rpcRevision)) { Optional<DataNodeContainer> potential = findInputOutput(rpc,targetType.getSimpleName()); if(potential.isPresent()) { return potential; } } } return Optional.absent(); }
@SuppressWarnings("checkstyle:illegalCatch") private static Optional<DataNodeContainer> findFirstDataNodeContainerInRpc(final SchemaContext ctx, final Class<? extends DataObject> targetType) { final QNameModule targetModule; try { targetModule = BindingReflections.getModuleInfo(targetType).getName().getModule(); } catch (Exception e) { throw new IllegalArgumentException( String.format("Failed to load module information for class %s", targetType), e); } for (RpcDefinition rpc : ctx.getOperations()) { if (targetModule.equals(rpc.getQName().getModule())) { final Optional<DataNodeContainer> potential = findInputOutput(rpc,targetType.getSimpleName()); if (potential.isPresent()) { return potential; } } } return Optional.empty(); }
SchemaNode child = ((DataNodeContainer) node).getDataChildByName(qname); if (child == null && node instanceof SchemaContext) { child = tryFind(((SchemaContext) node).getOperations(), qname).orElse(null);
SchemaNode child = ((DataNodeContainer) node).getDataChildByName(qname); if (child == null && node instanceof SchemaContext) { child = tryFind(((SchemaContext) node).getOperations(), qname).orElse(null);
private ContainerNodeCodecContext<?> createOperationDataContext(final Class<?> key) { Preconditions.checkArgument(Instantiable.class.isAssignableFrom(key)); final QName qname = BindingReflections.findQName(key); final QNameModule module = qname.getModule(); OperationDefinition operation = null; final SchemaContext schemaContext = getSchema(); if ((operation = findPotentialOperation(schemaContext.getOperations(), module, key, qname)) == null) { operation = findPotentialOperation(schemaContext.getActions(), module, key, qname); } Preconditions.checkArgument(operation != null, "Supplied class %s is not valid operation class.", key); final ContainerSchemaNode schema = getOperationDataSchema(operation, qname);// SchemaNodeUtils // .getRpcDataSchema(operation, qname); Preconditions.checkArgument(schema != null, "Schema for %s does not define input / output.", operation.getQName()); return (ContainerNodeCodecContext<?>) DataContainerCodecPrototype.from(key, schema, factory()).get(); }
private OperationDefinition findPotentialOperation(final Set<? extends OperationDefinition> set, final QNameModule module, final Class<?> key, final QName qname) { OperationDefinition operation = null; for (final OperationDefinition potential : getSchema().getOperations()) { final QName potentialQName = potential.getQName(); /* * Check if operation and class represents data from same module and then checks if operation * local name produces same class name as class name appended with Input/Output based on QName * associated with bidning class. * * FIXME: Rework this to have more precise logic regarding Binding Specification. */ final String moduleClassName = JavaIdentifierNormalizer .normalizeSpecificIdentifier(potentialQName.getLocalName(), JavaIdentifier.CLASS); final String keyClassName = JavaIdentifierNormalizer.normalizeSpecificIdentifier(qname.getLocalName(), JavaIdentifier.CLASS); if (module.equals(potentialQName.getModule()) && key.getSimpleName().equals(moduleClassName + keyClassName)) { operation = potential; break; } } return operation; }