odl源码系列一restconf模块

 

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
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值