【问题标题】:How can I manipulate the REST API GET generated by YANG in Opendaylight?如何在 Opendaylight 中操作 YANG 生成的 REST API GET?
【发布时间】:2018-05-30 18:21:06
【问题描述】:

PUT、DELETE、POST的操作如下图所示。

顺便说一句,我不知道该怎么做。

请帮帮我。

// PUT & DELETE (mapped to WRITE, DELETE of MD-SAL)
public void onDataTreeChanged(Collection<DataTreeModification<GreetingRegistry>> changes) {
  for(DataTreeModification<GreetingRegistry> change: changes) {
     DataObjectModification<GreetingRegistry> rootNode = change.getRootNode();
     if(rootNode.getModificationType() == WRITE) {
        ...
     }
     else if(rootNode.getModificationType() == DELETE) {
        ...
     }
}


// POST (mapped to RPC of MD-SAL)
public Future<RpcResult<HelloWorldOutput>> helloWorld(HelloWorldInput input) 
{
  HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();
  helloBuilder.setGreeting("Hello " + input.getName());
  return RpcResultBuilder.success(helloBuilder.build()).buildFuture();
}

// GET (???)
How should I implement it?

【问题讨论】:

    标签: opendaylight


    【解决方案1】:

    您实际上不必在代码中为 GET 实现任何内容,当您想从 YANG 建模的 MD-SAL 数据中读取时,GET 方法默认可用,并返回您在 URL 中要求的任何数据.指向正确的 URL 很重要。

    如果你想在返回给用户之前对数据进行一些处理,你可以使用 RPC 和 POST,并在基于 RPC 的方法中进行处理。在上面的示例中,您可以将搜索键放入HelloWorldInput,在helloWorld() 中进行处理,并在HelloWorldOutput 中返回结果。

    【讨论】:

    • 感谢您的帮助。当我发出 GET 请求时,我试图操纵数据库返回数据。这不可能吗?
    • 据我所知,是的。使用 GET 读取数据时,您不会收到通知,因此您无法对其做出反应。这就是为什么如果您想在读取时操作数据库,我推荐使用 RPC。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    相关资源
    最近更新 更多