opendaylight配置java环境_OpenDaylight开发环境搭建

本文详细介绍了如何在Ubuntu18.04上配置OpenDaylight开发环境,包括安装JDK8、Maven,下载ODL的settings.xml,生成ODL代码框架,编译并启动ODL控制器,实现RPC功能,并提供了相关参考资料。
摘要由CSDN通过智能技术生成

安装环境:Ubuntu18.04

一、安装依赖

1. 安装JDK:

sudo apt update

sudo apt install openjdk-8-jdk-headless

选择默认的 JDK:

~$ sudo update-alternatives --config java

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status

------------------------------------------------------------

* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode

1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode

2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode

Press to keep the current choice[*], or type selection number: 2

~$ java -version

设置 JAVA_HOME:

echo JAVA_HOME=export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 >> ~/.bashrc

source ~/.bashrc

2. 安装 maven:

sudo apt install maven

mvn -v

3. 安装 Sublime-Text3:(可选)

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -

sudo apt-get install apt-transport-https

echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

sudo apt-get update

sudo apt-get install sublime-text

二、搭建 ODL 代码框架

1. 获取配置 mvn 的 setting.xml:

~$ mkdir .m2

~$ wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml

如果无法下载,则可以拷贝以下内容:

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

opendaylight-release

opendaylight-mirror

opendaylight-mirror

https://nexus.opendaylight.org/content/repositories/public/

true

never

false

opendaylight-mirror

opendaylight-mirror

https://nexus.opendaylight.org/content/repositories/public/

true

never

false

opendaylight-snapshots

opendaylight-snapshot

opendaylight-snapshot

https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/

false

true

opendaylight-snapshot

opendaylight-snapshot

https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/

false

true

opendaylight-release

opendaylight-snapshots

View Code

2. 生成 odl 代码框架:

~$ mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeVersion=1.3.0-Carbon

Define value for property 'groupId': org.opendaylight.hello

Define value for property 'artifactId': hello

[INFO] Using property: version = 0.1.0-SNAPSHOT

Define value for property 'package' org.opendaylight.hello: :

Define value for property 'classPrefix' Hello: :

Define value for property 'copyright': ming

[INFO] Using property: copyrightYear = 2017

Confirm properties configuration:

groupId: org.opendaylight.hello

artifactId: hello

version: 0.1.0-SNAPSHOT

package: org.opendaylight.hello

classPrefix: Hello

copyright: ming

copyrightYear: 2017

Y: : y

3. 编译:

~$ cd hello/

~/hello$ mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true

4. 启动 odl 控制器:

~/hello$ cd karaf/target/assembly/bin

~/hello/karaf/target/assembly/bin$ ./karaf

opendaylight-user@root> feature:list | grep hello

5. Web 界面登录:

三、RPC 实现

1. 编写、编译 yang 文件:

文件:~/hello/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-world {

input {

leaf name {

type string;

}

}

output {

leaf greeting {

type string;

}

}

}

}

编译:(生成 RPC 定义等内容)

~/hello/api$ mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true

2. 编写 impl-blueprint.xml文件:

注册 RPC。

文件:~/hello/impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml

xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"

odl:use-default-for-reference-types="true">

interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"

odl:type="default" />

class="org.opendaylight.hello.impl.HelloProvider"

init-method="init" destroy-method="close">

3. 实现 RPC 处理函数:

文件:~/hello/impl/src/main/java/org/opendaylight/hello/impl/HelloProvider.java

package org.opendaylight.hello.impl;

import org.opendaylight.controller.md.sal.binding.api.DataBroker;

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.HelloWorldInput;

import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloWorldOutput;

import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloWorldOutputBuilder;

import org.opendaylight.yangtools.yang.common.RpcResult;

import org.opendaylight.yangtools.yang.common.RpcResultBuilder;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import java.util.concurrent.Future;

public class HelloProvider implements HelloService {

private static final Logger LOG = LoggerFactory.getLogger(HelloProvider.class);

private final DataBroker dataBroker;

public HelloProvider(final DataBroker dataBroker) {

this.dataBroker = dataBroker;

}

@Override

public Future> helloWorld(HelloWorldInput input) {

HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();

helloBuilder.setGreeting("Hello " + input.getName());

return RpcResultBuilder.success(helloBuilder.build()).buildFuture();

}

/**

* Method called when the blueprint container is created.

*/

public void init() {

LOG.info("HelloProvider Session Initiated");

}

/**

* Method called when the blueprint container is destroyed.

*/

public void close() {

LOG.info("HelloProvider Closed");

}

}

~/hello$ mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true

4. 启动 odl:

~/hello/karaf/target/assembly/bin$ ./karaf

5. 查看、测试 API:

打开:http://localhost:8181/apidoc/explorer/index.html

点击:hello(2015-01-05) -> post /operations/hello:hello-world

在参数部分输入:

{

"input": {

"name": "SDN"

}

}

点击:Try it out!

参考资料:

https://www.cnblogs.com/goldsunshine/p/11175698.html

https://www.cnblogs.com/leoych/p/13570303.html

https://docs.opendaylight.org/en/stable-aluminium/developer-guide/developing-apps-on-the-opendaylight-controller.html

https://www.cnblogs.com/goldsunshine/p/11176164.html

https://www.cnblogs.com/goldsunshine/p/11298951.html

标签:java,开发,yang,OpenDaylight,https,org,hello,opendaylight,搭建

来源: https://www.cnblogs.com/gzming/p/14239933.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值