odl北向接口基本是通过yang文件来定义,而北向接收到请求先得经过转化成标准的yang模型的api,再调用md-sal相关接口
入口项目为netconf 项目的restconf-nb-rfc8040,之前老的restconf-nb-bierman02已经废弃
入口类为JSONRestconfServiceRfc8040Impl, 这个类作为总北向入口,通过ServiceWrapper 作为代理来分发Put,get,delete,patch,post
invokeRpc等操作
构造器
@Inject
public JSONRestconfServiceRfc8040Impl(final ServicesWrapper services,
final DOMMountPointServiceHandler mountPointServiceHandler,
final SchemaContextHandler schemaContextHandler) {
this.services = services;
this.mountPointServiceHandler = mountPointServiceHandler;
this.schemaContextHandler = schemaContextHandler;
}
invokeRpc
@SuppressWarnings("checkstyle:IllegalCatch")
@SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF", justification = "Unrecognised NullableDecl")
@Override
public Optional<String> invokeRpc(final String uriPath, final Optional<String> input)
throws OperationFailedException {
requireNonNull(uriPath, "uriPath can't be null");
final String actualInput = input.isPresent() ? input.get() : null;
LOG.debug("invokeRpc: uriPath: {}, input: {}", uriPath, actualInput);
String output = null;
try {
# 将uripath转化成标准的yang模型相关的上下文
final NormalizedNodeContext inputContext = toNormalizedNodeContext(uriPath, actualInput, true);
LOG.debug("Parsed YangInstanceIdentifier: {}", inputContext.getInstanceIdentifierContext()
.getInstanceIdentifier());
LOG.debug("Parsed NormalizedNode: {}", inputContext.getData());
# 实际经过多层解析,会调用md-sal相关api来查找实际rpc地址,并调用
final NormalizedNodeContext outputContext =
services.invokeRpc(uriPath, inputContext, new SimpleUriInfo(uriPath));
if (outputContext.getData() != null) {
output = toJson(outputContext);
}
} catch (RuntimeException | IOException e) {
propagateExceptionAs(uriPath, e, "RPC");
}
return Optional.ofNullable(output);
}
一.解析url
首先会先通过url找到对应yang schema然后转换成对应Yang对应的上下文, 再转化成标准Node 的上下文
private NormalizedN