sudo apt-get install git
(1)官网下载jdk-8u162-linux-x64.tar.gz并拖入虚拟机桌面
(2)创建安装目录,并解压
cd /usr/local
sudo mkdir java
cd java
sudo mkdir jvm
sudo tar -zxvf ~/Desktop/jdk-8u162-linux-x64.tar.gz -C /usr/local/java/jvm
(3)配置
sudo gedit /etc/profile
#末尾加上如下
#set Java environment
export JAVA_HOME=/usr/local/java/jvm/jdk1.8.0_162
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
#同样,需要使用命令使环境变量立即生效
source /etc/profile
(4)检验
java -version
(5)多jdk问题处理
#注册
sudo update-alternatives --install /usr/bin/java java /usr/local/java/jvm/jdk1.8.0_162/bin/java 300
#注意,然后java –version 一下,没有的话,
sudo update-alternatives --install /usr/lib/java java /usr/local/java/jvm/jdk1.8.0_162/bin/java 300
#切换
sudo update-alternatives --config java
#选择jdk1.8.0_162,这里是输入序号,我的电脑是输入2.
(1)官网下载并拖入虚拟机桌面apache-maven-3.6.0-bin.tar
(2)创建安装目录,并解压
cd /opt
sudo mkdir maven
sudo tar -zxvf ~/Desktop/apache-maven-3.6.0-bin.tar.gz -C /opt/maven
(3)配置
sudo gedit /etc/profile
#jdk配置之前
#set maven environment
export MAVEN_HOME=/opt/maven/apache-maven-3.6.0
export PATH=${MAVEN_HOME}/bin:$PATH
#同样,需要使用命令使环境变量立即生效
source /etc/profile
(4)检查
mvn -v
说明:这里要先下载编译安装发行版本的原因在于,它会在~/.m2/repository目录下生成依赖包,而后面修改原型子项目中POM中的一些版本信息的时候可以参考对应目录下的包版本
cp -n ~/.m2/settings.xml{,.orig} ; wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
sudo git clone https://git.opendaylight.org/gerrit/p/integration/distribution.git
cd distribution
sudo git checkout stable/oxygen
git branch
#现在好像仓库里面的pom文件又变化了,要么别切分支要么切到弗版本
mvn clean install -DskipTests
cd karaf/target/assembly/bin
./karaf
feature:install odl-l2switch-switch
feature:install odl-openflowplugin-flow-services
feature:install odl-mdsal-all
feature:install odl-dlux-core odl-dluxapps-nodes odl-dluxapps-topology odl-dluxapps-yangui odl-dluxapps-yangvisualizer odl-dluxapps-yangman
说明:这里的项目原型迁移了,组id发生了变化,同时这里下载下来的项目原型的版本是最高版本,以前的版本的原型拿不到(比如Oxygen),同时官网doc的很多信息已经过时
mvn archetype:generate
-DarchetypeGroupId=org.opendaylight.archetypes
-DarchetypeArtifactId=opendaylight-startup-archetype
-DarchetypeCatalog=remote
-DarchetypeVersion=1.1.0-SNAPSHOT
用idea打开子项目,修改version信息
Oxygen要修改的(这里可能不是全部):
single-feature-parent 版本到3.1.4
odlparent-lite 版本到3.1.4
feature-repo-parent 版本到3.1.4
karaf4-parent 版本到 3.1.4
mdsal-artifacts 版本到1.7.5
binding-parent 版本到0.12.5-SNAPSHOT
利用~/.m2/repository来找到要修改的版本举例:
要修改的为
org.opendaylight.netconf
restconf-artifacts
那么查看的路径
~/.m2/repository/org/opendaylight/netconf/restconf-artifacts
cd 子项目名
mvn clean install
mvn idea:idea
说明:生成指令见3.1(1)
#按提示,输入要构建的子项目信息
Define value for property 'groupId': : com.ict.hello
Define value for property 'artifactId': : hello
Define value for property 'version'= 0.1.0-SNAPSHOT
Define value for property 'package': com.ict.hello: :
Define value for property 'classPrefix': Hello
Define value for property 'copyright': : Copyright (c) 2018 ict
说明:修改方法见3.1(2)
cd hello
mvn clean install
mvn idea:idea
1)编辑api/src/main/yang/hello.yang
module hello {
yang-version 1.1;
namespace "urn:opendaylight:params:xml:ns:yang:hello";
prefix "hello";
revision "2018-05-17" { // TODO change revision to date of model creation
description "Initial revision of hello model";
}
rpc hello-world {
input {
leaf name {
type string;
}
}
output {
leaf greating {
type string;
}
}
}
}
2)利用yang tool生成api
cd api
mvn clean install
1)编辑impl/src/main/java/com.ict.hello.impl
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;
}
/**
* 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");
}
@Override
public Future> helloWorld(HelloWorldInput input) {
HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();
helloBuilder.setGreating("Hello World " + input.getName());
return RpcResultBuilder.success(helloBuilder.build()).buildFuture();
}
2)编译
cd impl
mvn clean install
说明:这里利用其来进行依赖注入
建议:注释掉pom.xml里面的it,它在test的时候比较费时间
cd hello
mvn clean install
cd karaf/target/assembly/bin
./karaf
log:display | grep hello
feature:list | grep hello
1)请求类型及地址
POST
http://your_ip:8181/restconf/operations/hello:hello-world
说明:这里的ip地址是controller的IP地址,helloworld前缀和rpc hello-world在yang文件中定义。
2)修改Authorization
类型选择Basic Auth
Username:admin
Password:admin
3)Body,raw,json(application/json)
{"input": {
"name": "Andrew"
}
}
4)结果
{
"output": {
"greating": "Hello World Andrew"
}
}
#子项目路径/karaf/target/assembly/system/子项目组名路径
#复制到
#distribution odl目录/karaf/target/assembly/system/子项目组名路径
#example:(以com.ict.hello为例,因为这里这个包下只有一个项目,所有我直接移动了ict目录)
sudo cp -r /opt/ODLWorkspace/hello/karaf/target/assembly/system/com/ict /opt/ODL/integration/distribution/karaf/target/assembly/system/com
cd odl目录/karaf/target/assembly/bin
./karaf
feature:repo-add mvn:com.ict.hello/features-hello/0.1.0-SNAPSHOT/xml/features
feature:install odl-restconf-all
feature:install odl-hello
#启动控制器后,浏览器打开
http://localhost:8181/index.html#/yangui/index
#Expendall 查看是否有hello
#点击
hello
opreational
hello-world
#input 输入,然后点击send
#这里output有时候不知道为啥,看不到输出,点击history查看
#idea添加远程监听端口5005
#(这里的odl目录可以是发行版本也可以是自己的子项目)
#给代码打上断点
cd odl目录/karaf/target/assembly/bin
./karaf debug
#在项目的features-项目名称中直接添加
#比如
org.opendaylight.l2switch
odl-l2switch-switch
0.7.5-SNAPSHOT
xml
features
org.opendaylight.openflowplugin
odl-openflowplugin-flow-services
0.6.5-SNAPSHOT
xml
features
org.opendaylight.controller
odl-mdsal-all
1.7.5-SNAPSHOT
xml
features
#重新mvn clean install
#但是它不是自动安装,只是不用再在karaf中add,但是依旧需要install.
#因为可以直接利用发行版本来调试,所以建议将自己开发的插件加入到发行版本,来调试
#在修改的时候记得uninstall