odl-boron-sr3之hello rpc
来源:互联网 发布:网络小精灵国语版58网 编辑:程序博客网 时间:2024/06/05 18:57
环境安装,请看这里。
之前的文章,已经建立了hello,详情看这里。
现在做一个hello的rpc。官方文档看这里。
环境:odl-boron-sr3和mvn和java
ps:本篇文章只有过程,没有细致讲解(因为我也不太懂呀)
1.添加rpc api:
编辑api/src/main/yang/hello.yang,修改为下面代码(这里新增了输入和输出)
module hello { yang-version 1; namespace "urn:opendaylight:params:xml:ns:yang:hello"; prefix "hello"; revision "2015-01-05" { description "Initial revision of hello model"; } rpc hello { input { leaf name { type string; } } output { leaf greeting { type string; } } }}
2.进到api文件夹执行mvn clean install
3.实现rpc api:
进入impl/src/main/java/org/bupt/siwind/hello/impl,然后新建文件HelloImpl.java并填入下面代码。
ps:最前面的/**/不要删,可能回报错。
/* * Copyright © 2016 Pn, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */package org.bupt.siwind.hello.impl;import java.util.concurrent.Future;import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloService;import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloInput;import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloOutput;import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloOutputBuilder;import org.opendaylight.yangtools.yang.common.RpcResult;import org.opendaylight.yangtools.yang.common.RpcResultBuilder;public class HelloImpl implements HelloService { @Override public Future<RpcResult<HelloOutput>> hello(HelloInput input) { HelloOutputBuilder helloBuilder = new HelloOutputBuilder(); helloBuilder.setGreeting("Hello " + input.getName()); return RpcResultBuilder.success(helloBuilder.build()).buildFuture(); }}
再编辑HelloProvider.java,修改为下面代码(init函数启动时会调用hello rpc):
ps:最前面的/**/不要删,可能回报错。
/* * Copyright © 2016 Pn, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */package org.bupt.siwind.hello.impl;import org.opendaylight.controller.md.sal.binding.api.DataBroker;import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloService;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class HelloProvider { private static final Logger LOG = LoggerFactory.getLogger(HelloProvider.class); private final DataBroker dataBroker; private final RpcProviderRegistry rpcProviderRegistry; private RpcRegistration<HelloService> serviceRegistration; public HelloProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry) { this.dataBroker = dataBroker; this.rpcProviderRegistry = rpcProviderRegistry; } /** * Method called when the blueprint container is created. */ public void init() { serviceRegistration = rpcProviderRegistry.addRpcImplementation(HelloService.class, new HelloImpl()); LOG.info("helloProvider Session Initiated"); } /** * Method called when the blueprint container is destroyed. */ public void close() { serviceRegistration.close(); LOG.info("helloProvider Closed"); }}
3.注册rpc api:
编辑impl/src/main/resources/org/opendaylight/blueprint下的impl-blueprint.xml,修改为下面代码:
ps:最前面的/**/不要删,可能回报错。
<?xml version="1.0" encoding="UTF-8"?><!-- vi: set et smarttab sw=4 tabstop=4: --><!--Copyright © 2016 Pn, Inc. and others. All rights reserved.This program and the accompanying materials are made available under theterms of the Eclipse Public License v1.0 which accompanies this distribution,and is available at http://www.eclipse.org/legal/epl-v10.html--><blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0" odl:use-default-for-reference-types="true"> <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker" odl:type="default" /> <reference id="rpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/> <bean id="provider" class="org.bupt.siwind.hello.impl.HelloProvider" init-method="init" destroy-method="close"> <argument ref="dataBroker" /> <argument ref="rpcRegistry" /> </bean></blueprint>
4.到impl文件夹中执行mvn clean install
5.到hello文件夹中执行mvn clean install
6.运行./karaf/target/assembly/bin/karaf
执行log:display | grep Hello
输出没有error,就说明成功了。
7.测试rest,用postman或相关软件。
url:http://127.0.0.1:8181/restconf/operations/hello:hello
method:post
basic auth:admin admin
body:
{"input": { "name": "Songqiu" }}
- odl-boron-sr3之hello rpc
- opendaylight-Boron-SR3开发入门实例
- 在odl中如何实现rpc
- Win32 RPC Demo之Hello World
- rpc框架之gRPC 学习 - hello world
- SDN相关组织之ODL(opendaylight)
- ODL学习笔记(二)OpenDayLight的第一个项目-Hello World
- Python RPC 之 xml-rpc
- ODL参考手册
- 【RPC框架Hessian一】Hessian RPC Hello World
- spring-cloud-eureka-server之spring-cloud-1.3.4(Dalston.SR3)-boot(1.5.6) 学习笔记
- spring-cloud-eureka-client之spring-cloud-1.3.4(Dalston.SR3)-boot(1.5.6) 学习笔记
- spring-cloud-feign之spring-cloud-1.3.4(Dalston.SR3)-boot(1.5.6) 学习笔记
- spring-cloud-ribbon之spring-cloud-1.3.4(Dalston.SR3)-boot(1.5.6) 学习笔记
- spring-cloud-hystrix之spring-cloud-1.3.4(Dalston.SR3)-boot(1.5.6) 学习笔记
- spring-cloud-zuul之spring-cloud-1.3.4(Dalston.SR3)-boot(1.5.6) 学习笔记
- Linux下RPC的hello world
- JAX-RPC学习笔记(1)-Hello World!
- 小波变换
- [JZOJ5336] 提米树
- JavaSE 网络编程
- SpringMVC拦截器实现登录验证的例子
- 解决Ubuntu 切换root失败问题
- odl-boron-sr3之hello rpc
- 找到B字符串在A字符串中出现的所有位置的集合
- hdu 6161
- 自己搭建自动化巡检系统(一) 环境准备系统连接gns3
- numpy中函数nditer的作用
- caffe-windows添加自己的工程
- oracle子查询嵌套查询
- QT5布局管理——分割窗口QSplitter类
- 线段树题目整合