在上一节中将ODL的开发工具都装好,mvn是生成ODL框架的管理器。在本节中使用mvn构建ODL开发的代码框架。 

 

1|0一、生成ODL代码框架

 

maven工具根据上一节中设置的setting文件生成ODL的框架代码。使用代码框架的好处是不用从零开始写,框架将基础的代码写好,我们只需要关注自己的业务代码。

mvn archetype:generate DarchetypeGroupId=org.opendaylight.controller DarchetypeArtifactId=opendaylightstartuparchetype DarchetypeVersion=1.3.0Carbon

root@vm:~# mvn org.apache.maven.plugins:mavenarchetypeplugin:2.4:generate DarchetypeGroupId=org.opendaylight.controller DarchetypeArtifactId=opendaylightstartuparchetype DarchetypeRepository=https://nexus.opendaylight.org/content/repositories/public -DarchetypeVersion=1.3.2-Carbon
[INFO] Scanning for projects
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.pom (9 KB at 2.7 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/archetype/maven-archetype/2.4/maven-archetype-2.4.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/archetype/maven-archetype/2.4/maven-archetype-2.4.pom (13 KB at 22.8 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/maven-parent/26/maven-parent-26.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/maven-parent/26/maven-parent-26.pom (39 KB at 46.9 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/apache/16/apache-16.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/apache/16/apache-16.pom (16 KB at 27.5 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.jar
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.jar (92 KB at 105.9 KB/sec)
[INFO]
[INFO] ————————————————————————
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ————————————————————————
[INFO]
[INFO] >>> mavenarchetypeplugin:2.4:generate (defaultcli) > generatesources @ standalonepom >>>
[INFO]
[INFO] <<< mavenarchetypeplugin:2.4:generate (defaultcli) < generatesources @ standalonepom <<<
[INFO]
[INFO] mavenarchetypeplugin:2.4:generate (defaultcli) @ standalonepom

Define value for property ‘groupId’: : org.opendaylight.example
Define value for property ‘artifactId’: : example
[INFO] Using property: version = 0.1.0SNAPSHOT
Define value for property ‘package’: org.opendaylight.topology: :
Jul 12, 2019 2:36:35 PM org.apache.velocity.runtime.log.JdkLogChute log
INFO: FileResourceLoader : adding path ‘.’
Define value for property ‘classPrefix’: Topology: :
Define value for property ‘copyright’: : worker
[INFO] Using property: copyrightYear = 2017
Confirm properties configuration:
groupId: org.opendaylight.topology
artifactId: topology
version: 0.1.0SNAPSHOT
package: org.opendaylight.topology
classPrefix: Topology
copyright: worker
copyrightYear: 2017
Y: : y

[INFO] —————————————————————————-
[INFO] Using following parameters for creating project from Archetype: opendaylightstartuparchetype:1.3.2Carbon
[INFO] —————————————————————————-
[INFO] Parameter: groupId, Value: org.opendaylight.topology
[INFO] Parameter: artifactId, Value: topology
[INFO] Parameter: version, Value: 0.1.0SNAPSHOT
[INFO] Parameter: package, Value: org.opendaylight.topology
[INFO] Parameter: packageInPathFormat, Value: org/opendaylight/topology
[INFO] Parameter: classPrefix, Value: Topology
[INFO] Parameter: package, Value: org.opendaylight.topology
[INFO] Parameter: version, Value: 0.1.0SNAPSHOT
[INFO] Parameter: copyright, Value: worker
[INFO] Parameter: groupId, Value: org.opendaylight.topology
[INFO] Parameter: artifactId, Value: topology
[INFO] Parameter: copyrightYear, Value: 2017
[WARNING] Don‘t override file /root/topology/pom.xml
[INFO] project created from Archetype in dir: /root/topology
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 03:53 min
[INFO] Finished at: 2019-07-12T14:36:59+08:00
[INFO] Final Memory: 16M/38M
[INFO] ————————————————————————

 

当命令执行结束之后,会生成一个ODL的代码框架。具体内容有如下:

 

文件名 功能
api Yang模型目录
artifacts 项目组件坐标管理
cli 部署的配置文件
features feature组织管理目录
impl 业务逻辑的代码实现目录
it 集成测试
karaf karaf打包目录
pom.xml maven项目的基本信息描述文件

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2|0二、编译ODL框架代码


将ODL框架代码编译之后就能运能一个最简单的ODL控制器,该控制器没有任何多余功能。

提示:这个过程会持续半个小时以上时间,并且可能会连接超时而报错,具体长短取决于你的机器性能和网络。确保你在执行这个动作之前是在工程的根目录下。

mvn clean install DskipTests Dmaven.javadoc.skip=true Dcheckstyle.skip=true

 参数:
-DskipTests表示不执行测试用例
-Dmaven.javadoc.skip=true表示跳过javadoc
-Dcheckstyle.skip=true表示跳过checkstyle检查

  

root@vm:~/topology# pwd
/root/example
root@vm:~/topology# mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
[INFO] Scanning for projects
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent/1.8.2-Carbon/odlparent-1.8.2-Carbon.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent/1.8.2-Carbon/odlparent-1.8.2-Carbon.pom (77 KB at 26.6 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent-lite/1.8.2-Carbon/odlparent-lite-1.8.2-Carbon.pom
Downloaded: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/odlparent/odlparent-lite/1.8.2-Carbon/odlparent-lite-1.8.2-Carbon.pom (18 KB at 30.4 KB/sec)
Downloading: https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/mdsal/binding-parent/0.10.2-Carbon/binding-parent-0.10.2-Carbon.pom

[INFO] Feature repository discovered recursively: standard3.0.8
[INFO] Feature repository discovered recursively: enterprise3.0.8
[INFO] Feature repository discovered recursively: org.ops4j.pax.web3.2.9
[INFO] Feature repository discovered recursively: spring3.0.8
[INFO] Feature repository discovered recursively: odltopology0.1.0SNAPSHOT
[INFO] Feature repository discovered recursively: odltopology0.1.0SNAPSHOT
[INFO] Feature repository discovered recursively: odlyangtools1.1.2Carbon
[INFO] Feature repository discovered recursively: odlparent1.8.2Carbon
[INFO] Feature repository discovered recursively: odlnetty4
[INFO] Feature repository discovered recursively: odlguava18
[INFO] Feature repository discovered recursively: odlguava21
[INFO] Feature repository discovered recursively: odllmax3
[INFO] Feature repository discovered recursively: odltriemap0.2
[INFO] Feature repository discovered recursively: odlmdsalmodels0.10.2Carbon
[INFO] Feature repository discovered recursively: odlyangtools2.2.2Carbon
[INFO] Feature repository discovered recursively: odlmdsal1.5.2Carbon
[INFO] Feature repository discovered recursively: odlcontroller1.8.2Carbon
[INFO] Feature repository discovered recursively: odlakkaall
[INFO] Feature repository discovered recursively: odlakkascala2.11
[INFO] Feature repository discovered recursively: odlakkasystem2.4
[INFO] Feature repository discovered recursively: odlakkaclustering2.4
[INFO] Feature repository discovered recursively: odlakkaleveldb0.7
[INFO] Feature repository discovered recursively: odlakkapersistence2.4
[INFO] Feature repository discovered recursively: odlconfig0.6.2Carbon
[INFO] Feature repository discovered recursively: odlconfigpersister0.6.2Carbon
[INFO] Feature repository discovered recursively: odlconfigpersister0.6.2Carbon
[INFO] Feature repository discovered recursively: odlcontroller1.5.2Carbon
[INFO] Feature repository discovered recursively: odlaaa0.5.2Carbon
[INFO] Feature repository discovered recursively: odlaaa0.5.2Carbon
[INFO] Feature repository discovered recursively: odldlux0.5.2Carbon
[INFO] Feature repository discovered recursively: odldlux0.5.2Carbon
[INFO] Feature repository discovered recursively: standard3.0.8
[INFO] Feature repository discovered recursively: org.ops4j.pax.web3.2.9[INFO]Feature repository discovered recursively: org.ops4j.pax.cdi0.11.0[INFO]Feature repository discovered recursively: odlyangtools1.1.2Carbon[INFO]Feature repository discovered recursively: odlparent1.8.2Carbon[INFO]Feature repository discovered recursively: odlmdsal1.5.2Carbon[INFO]Feature repository discovered recursively: odlyangtools2.2.2Carbon[INFO]Feature repository discovered recursively: odlmdsalmodels0.10.2Carbon[INFO]Feature repository discovered recursively: odlconfig0.6.2Carbon[INFO]Feature repository discovered recursively: odlconfigpersister0.6.2Carbon[INFO]Feature repository discovered recursively: odlconfigpersister0.6.2Carbon[INFO]Feature repository discovered recursively: odlcontroller1.8.2Carbon[INFO]Feature repository discovered recursively: odlcontroller1.5.2Carbon[INFO]Feature repository discovered recursively: odlaaa0.5.2Carbon[INFO]Feature repository discovered recursively: odlaaa0.5.2Carbon[INFO]Feature repository discovered recursively: odldlux0.5.2Carbon[INFO]Feature repository discovered recursively: odldlux0.5.2Carbon[INFO]Feature repository discovered recursively: odlakkascala2.11[INFO]Feature repository discovered recursively: odlakkasystem2.4[INFO]Feature repository discovered recursively: odlakkaclustering2.4[INFO]Feature repository discovered recursively: odlakkaleveldb0.7[INFO]Feature repository discovered recursively: odlakkapersistence2.4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[INFO]
[INFO] --- maven-site-plugin:3.6:attach-descriptor (generate-site) @ example-aggregator ---
[INFO] Attaching 'src/site/site.xml' site descriptor with classifier 'site'.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] ODL :: org.opendaylight.example :: example-api ..... SUCCESS [ 34.400 s]
[INFO] ODL :: org.opendaylight.example :: example-impl .... SUCCESS [  3.889 s]
[INFO] ODL :: org.opendaylight.example :: example-cli ..... SUCCESS [  3.516 s]
[INFO] ODL :: org.opendaylight.example :: example-features  SUCCESS [07:59 min]
[INFO] ODL :: org.opendaylight.example :: example-karaf ... SUCCESS [12:00 min]
[INFO] ODL :: org.opendaylight.example :: example-artifacts SUCCESS [  3.710 s]
[INFO] ODL :: org.opendaylight.example :: example-it ...... SUCCESS [ 18.773 s]
[INFO] example ............................................ SUCCESS [ 25.075 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21:41 min
[INFO] Finished at: 2019-07-29T19:33:48+08:00
[INFO] Final Memory: 210M/888M
[INFO] ------------------------------------------------------------------------

  

3|0三、编译完成


当编译完成之后,文件夹下会生成target

 

 

启动ODL控制器

进入bin目录下,运行./karaf脚本,启动ODL控制器。

 

 

查看此时安装的插件,只有简单的UI,命令行,API等。

 

 

ODL界面

 

  

 

简单总结一下本篇的内容。本篇主要是下载ODL框架代码,然后编译java源码,生成一个最简单的ODL控制器。本篇还有到ODL的功能开发,所有该ODL只有最简单的插件。

 

 本文作者:goldsunshine
本文链接:https://www.cnblogs.com/goldsunshine/p/11176164.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!