1. 程式人生 > >opendaylight-Boron-SR3開發入門例項

opendaylight-Boron-SR3開發入門例項

開發環境搭建:
開發環境配置如下:
1) 64位ubuntu16.04系統,4G以上記憶體, 16G以上硬碟剩餘空間
2) JDK8, maven-3.5.0(原始碼安裝)
3) 環境變數設定(gedit /etc/profilesource /etc/profile)

export JAVA_HOME=…
export MAVEN_OPTS="-Xmx4G"

注:MAVEN_OPTS是設定記憶體的(記憶體小給1024m),java是sudo apt-get install oracle-java8-installer 安裝的就可以不用填export JAVA_HOME=…

開發示例專案(預設hello):


0) 獲取ODL的maven配置檔案(用於maven編譯時下載ODL的相應jar檔案)

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

注:關於.m2資料夾:
安裝完maven是沒有.m2資料夾的。在Linux中以.開頭的資料夾都是隱藏的。當使用maven命令(例如mvn help:system)的時候,maven自動會建立.m2資料夾(可用ll檢視)。
1.repository
所有的maven構件,都儲存在repository中。比如本機中的使用maven的專案所以來的jar包,下載後都會存放在此處。
2.settings.xml
settings.xml存在maven根目錄下conf中,安裝maven後其實是根本不存在的。
1) 用maven生成專案框架(設專案為hello)
說明:
對於Boron SR0,使用Archetype-Version = 1.2.0-Boron
對於Boron SR1,使用Archetype-Version = 1.2.1-Boron-SR1
對於Boron SR2,使用Archetype-Version = 1.2.2-Boron-SR2
按版本修改下面第一個命令中的DarchetypeVersion

# mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype \
-DarchetypeRepository=http://nexus.opendaylight.org/content/repositories/opendaylight.release/ \
-DarchetypeCatalog=remote -DarchetypeVersion=1.2.3-Boron-SR3
#
Define value for
property 'groupId': org.bupt.siwind.hello Define value for property 'artifactId': hello Define value for property 'package': org.bupt.siwind.hello: : (回車) Define value for property 'classPrefix': (回車) Define value for property 'copyright': : Pn, Inc. Y: : (回車)

2) 編譯執行

cd hello/
mvn clean install

注:檔案在/.m2/repository/org/bupt/

#./karaf/target/assembly/bin/karaf
opendaylight-user@root>feature:list -i | grep hello
opendaylight-user@root>log:display | grep Hello

可以看到hello已經安裝。

3) 將hello安裝到生產odl中
i)拷貝:假設當前正常部署執行的ODL發行版位於: /opt/distribution-karaf-0.5.3-Boron-SR3

當前的hello專案位於/root/hello

那麼拷貝命令如下:

#cp -R /root/hello/karaf/target/assembly/system/org/bupt /opt/distribution-karaf-0.5.3-Boron-SR3/system/org

ii)檢視hello的maven路徑:

#cd hello (進入hello專案目錄)
#cat ./karaf/target/assembly/etc/org.apache.karaf.features.cfg

檢視這一行:featuresRepositories
在最後有hello的mvn路徑: mvn:org.bupt.siwind.hello/hello-features/0.1.0-SNAPSHOT/xml/features

iii)執行ODL並新增和安裝hello的bundle:

#cd /opt/distribution-karaf-0.5.3-Boron-SR3
#./bin/karaf (啟動ODL執行,或者以乾淨模式啟動: ./bin/karaf clean)
#[email protected]>feature:repo-add mvn:org.bupt.siwind.hello/hello-features/0.1.0-SNAPSHOT/xml/features
# [email protected]>feature:install odl-hello-ui
# [email protected]> feature:list| grep hello
# [email protected]> log:display| grep Hello

可以看到執行結果正常。
(移除bundle)

#opendaylight@root>feature:repo-remove mvn:org.bupt.siwind.hello/hello-features/0.1.0-SNAPSHOT/xml/features

參考資料