OpenDaylight开发hello-world项目之开发环境搭建
OpenDaylight开发hello-world项目之开发工具安装
OpenDaylight开发hello-world项目之代码框架搭建
在上一节中将ODL的开发工具都装好,mvn是生成ODL框架的管理器。在本节中使用mvn构建ODL开发的代码框架。
一、生成ODL代码框架
maven工具根据上一节中设置的setting文件生成ODL的框架代码。使用代码框架的好处是不用从零开始写,框架将基础的代码写好,我们只需要关注自己的业务代码。
mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeVersion=1.3.0-Carbon
root@vm:~# mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype -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] >>> maven-archetype-plugin:2.4:generate (default-cli) > generate-sources @ standalone-pom >>> [INFO] [INFO] <<< maven-archetype-plugin:2.4:generate (default-cli) < generate-sources @ standalone-pom <<< [INFO] [INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom ---
Define value for property 'groupId': : org.opendaylight.example Define value for property 'artifactId': : example [INFO] Using property: version = 0.1.0-SNAPSHOT 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.0-SNAPSHOT package: org.opendaylight.topology classPrefix: Topology copyright: worker copyrightYear: 2017 Y: : y
[INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Archetype: opendaylight-startup-archetype:1.3.2-Carbon [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: org.opendaylight.topology [INFO] Parameter: artifactId, Value: topology [INFO] Parameter: version, Value: 0.1.0-SNAPSHOT [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.0-SNAPSHOT [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打包目录 |
src | |
pom.xml | maven项目的基本信息描述文件 |
二、编译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: standard-3.0.8 [INFO] Feature repository discovered recursively: enterprise-3.0.8 [INFO] Feature repository discovered recursively: org.ops4j.pax.web-3.2.9 [INFO] Feature repository discovered recursively: spring-3.0.8 [INFO] Feature repository discovered recursively: odl-topology-0.1.0-SNAPSHOT [INFO] Feature repository discovered recursively: odl-topology-0.1.0-SNAPSHOT [INFO] Feature repository discovered recursively: odl-yangtools-1.1.2-Carbon [INFO] Feature repository discovered recursively: odlparent-1.8.2-Carbon [INFO] Feature repository discovered recursively: odl-netty-4 [INFO] Feature repository discovered recursively: odl-guava-18 [INFO] Feature repository discovered recursively: odl-guava-21 [INFO] Feature repository discovered recursively: odl-lmax-3 [INFO] Feature repository discovered recursively: odl-triemap-0.2 [INFO] Feature repository discovered recursively: odl-mdsal-models-0.10.2-Carbon [INFO] Feature repository discovered recursively: odl-yangtools-2.2.2-Carbon [INFO] Feature repository discovered recursively: odl-mdsal-1.5.2-Carbon [INFO] Feature repository discovered recursively: odl-controller-1.8.2-Carbon [INFO] Feature repository discovered recursively: odl-akka-all [INFO] Feature repository discovered recursively: odl-akka-scala-2.11 [INFO] Feature repository discovered recursively: odl-akka-system-2.4 [INFO] Feature repository discovered recursively: odl-akka-clustering-2.4 [INFO] Feature repository discovered recursively: odl-akka-leveldb-0.7 [INFO] Feature repository discovered recursively: odl-akka-persistence-2.4 [INFO] Feature repository discovered recursively: odl-config-0.6.2-Carbon [INFO] Feature repository discovered recursively: odl-config-persister-0.6.2-Carbon [INFO] Feature repository discovered recursively: odl-config-persister-0.6.2-Carbon [INFO] Feature repository discovered recursively: odl-controller-1.5.2-Carbon [INFO] Feature repository discovered recursively: odl-aaa-0.5.2-Carbon [INFO] Feature repository discovered recursively: odl-aaa-0.5.2-Carbon [INFO] Feature repository discovered recursively: odl-dlux-0.5.2-Carbon [INFO] Feature repository discovered recursively: odl-dlux-0.5.2-Carbon [INFO] Feature repository discovered recursively: standard-3.0.8 [INFO] Feature repository discovered recursively: org.ops4j.pax.web-3.2.9 [INFO] Feature repository discovered recursively: org.ops4j.pax.cdi-0.11.0 [INFO] Feature repository discovered recursively: odl-yangtools-1.1.2-Carbon [INFO] Feature repository discovered recursively: odlparent-1.8.2-Carbon [INFO] Feature repository discovered recursively: odl-mdsal-1.5.2-Carbon [INFO] Feature repository discovered recursively: odl-yangtools-2.2.2-Carbon [INFO] Feature repository discovered recursively: odl-mdsal-models-0.10.2-Carbon [INFO] Feature repository discovered recursively: odl-config-0.6.2-Carbon [INFO] Feature repository discovered recursively: odl-config-persister-0.6.2-Carbon [INFO] Feature repository discovered recursively: odl-config-persister-0.6.2-Carbon [INFO] Feature repository discovered recursively: odl-controller-1.8.2-Carbon [INFO] Feature repository discovered recursively: odl-controller-1.5.2-Carbon [INFO] Feature repository discovered recursively: odl-aaa-0.5.2-Carbon [INFO] Feature repository discovered recursively: odl-aaa-0.5.2-Carbon [INFO] Feature repository discovered recursively: odl-dlux-0.5.2-Carbon [INFO] Feature repository discovered recursively: odl-dlux-0.5.2-Carbon [INFO] Feature repository discovered recursively: odl-akka-scala-2.11 [INFO] Feature repository discovered recursively: odl-akka-system-2.4 [INFO] Feature repository discovered recursively: odl-akka-clustering-2.4 [INFO] Feature repository discovered recursively: odl-akka-leveldb-0.7 [INFO] Feature repository discovered recursively: odl-akka-persistence-2.4
[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] ------------------------------------------------------------------------
三、编译完成
当编译完成之后,文件夹下会生成target
启动ODL控制器
进入bin目录下,运行./karaf脚本,启动ODL控制器。
查看此时安装的插件,只有简单的UI,命令行,API等。
ODL界面
简单总结一下本篇的内容。本篇主要是下载ODL框架代码,然后编译java源码,生成一个最简单的ODL控制器。本篇还有到ODL的功能开发,所有该ODL只有最简单的插件。