研一时在 opendaylight 控制器上开发过路由插件,当时开发时半懂不懂的,很多东西都没弄清楚。最近为找找工作做准备,准备重新好好学习 opendatlight。
opendatlight 源码中涉及到的知识有:maven,OSGI,karaf,yang 技术;Config Subsystem,MD-SAL,MD-SAL Clustering 子系统;NETCONF,RESTCONF 协议。

maven

At first glance Maven can appear to be many things, but in a nutshell Maven is an attempt to apply patterns to a project’s build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool and as such provides a way to help with managing:

  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Distribution
  • Releases

maven 是项目管理工具,确实很好用。自己接触过的使用 maven 管理的项目:opendaylight,spring,hibernate。

pom.xml 文件标签详解:https://maven.apache.org/pom.html
配置参考网址:https://maven.apache.org/settings.html

可以打开一个项目的 pom.xml 查看,遇到不认得的标签就去上面网页查,这样学习比较快。
我觉得理解了 pom.xml 文件标签含义和 maven 工具的配置,就算 maven 入门了。

顺便附一个官网入门指南:https://maven.apache.org/guides/getting-started/index.html
因为自己原来已经接触过 maven 了,对自己用处不太大。

maven 插件

深入学习的话,需要学习 maven 强大的插件功能。
https://maven.apache.org/plugins/index.html

我们都知道Maven本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给插件来完成,例如编译源代码是由maven-compiler-plugin完成的。进一步说,每个任务对应了一个插件目标(goal),每个插件会有一个或者多个目标,例如maven-compiler-plugin的compile目标用来编译位于src/main/java/目录下的主源码,testCompile目标用来编译位于src/test/java/目录下的测试源码。

用户可以通过两种方式调用Maven插件目标。第一种方式是将插件目标与生命周期阶段(lifecycle phase)绑定,这样用户在命令行只是输入生命周期阶段而已,例如Maven默认将maven-compiler-plugin的compile目标与compile生命周期阶段绑定,因此命令mvn compile实际上是先定位到compile这一生命周期阶段,然后再根据绑定关系调用maven-compiler-plugin的compile目标。第二种方式是直接在命令行指定要执行的插件目标,例如mvn archetype:generate 就表示调用maven-archetype-plugin的generate目标,这种带冒号的调用方式与生命周期无关。

maven plugin 案例分析

在 opendaylight 的各个子项目中都引入了 maven-bundle-plugin,下面列出 routing 中 pom.xml 部分内容。

<build><plugins><plugin><groupId>org.apache.felix</groupId><artifactId>maven-bundle-plugin</artifactId><extensions>true</extensions><configuration><instructions><Import-Package>org.slf4j,org.opendaylight.controller.sal.routing,org.opendaylight.controller.sal.core,org.opendaylight.controller.sal.topology,org.opendaylight.controller.sal.utils,org.opendaylight.controller.sal.reader,org.opendaylight.controller.clustering.services,org.apache.commons.collections15,org.opendaylight.controller.switchmanager,org.opendaylight.controller.topologymanager,edu.uci.ics.jung.graph,edu.uci.ics.jung.algorithms.shortestpath,edu.uci.ics.jung.graph.util,org.apache.felix.dm,org.osgi.framework,org.apache.felix.service.command,org.junit;resolution:=optional</Import-Package><Bundle-Activator>org.opendaylight.controller.routing.dijkstra_implementation.internal.Activator</Bundle-Activator></instructions><manifestLocation>${project.basedir}/META-INF</manifestLocation></configuration></plugin></plugins></build>

网上查看 maven-bundle-plugin 的执行目标信息如下:

General Information about the goals.

bundle:bundle Create an OSGi bundle from Maven project. (life-cycle goal)
bundle:manifest Generate an OSGi manifest for this project.
bundle:cleanVersions Convert a group of versions to OSGi format.
bundle:instructions Generate BND instructions for this project.
bundle:install Installs bundle details in the local OBR repository. (life-cycle goal)
bundle:deploy Deploys bundle details to a remote OBR repository. (life-cycle goal)
bundle:index Index the content of a maven repository using OBR.
bundle:install-file Installs bundle details in the local OBR repository. (command-line goal)
bundle:deploy-file Deploys bundle details to a remote OBR repository. (command-line goal)
bundle:clean Clean a local OBR repository by finding and removing missing resources.
bundle:remote-clean Clean a remote OBR repository by finding and removing missing resources.
bundle:ant Generate Ant script to create the bundle. (you should run ant:ant first)

可以看出这个插件中部分 goals 是与生命周期绑定的,部分没有。我们执行 maven:install 其实调用的 bundle:install 功能。

再附上几个我原来看过的中文网址:

  1. Apache Maven 入门篇 ( 上 )
  2. Apache Maven 入门篇 ( 下 )
  3. 细致全面的Maven教程
  4. maven 插件介绍
  5. maven-bundle-plugin

待解决疑惑:

opendaylight 提供的 settings.xml 文件中,有两个 activeProfile 标签,看网上的解释说可以激活多个 profile,那都激活后哪一个会起作用?

<activeProfiles><activeProfile>opendaylight-release</activeProfile><activeProfile>opendaylight-snapshots</activeProfile></activeProfiles>

参考网址:http://blog.csdn.net/taiyangdao/article/details/52311257

OSGI 入门

OSGI 是一个标准,实现这个标准的产品有:apache felix,Equinox等。

OSGI 架构图

OSGI 可以分为三层:模块层,生命周期层,服务层。
每一层的学习可以看下面的入门教程。

参考书目和文档:

  1. 《深入理解OSGi Equinox原理、应用与最佳实践》,讲的很详细。
  2. 官网文档
  3. 中文社区
  4. 入门教程
  5. OSGi Core Release 6 Specification
  6. 里面有 Specifications,Javadoc,XML Schemas 等内容

karaf

Karaf Container is a modern and polymorphic container.It’s a lightweight, powerful, and enterprise ready container powered by OSGi.

karaf 架构图

Karaf安装目录结构如下:

/bin: 启动脚本
/etc: 初始化文件
/data: 工作目录
/cache: OSGi框架包缓存
/generated-bundles: 部署使用的临时文件夹
/log: 日志文件
/deploy: 热部署目录
/instances: 含有子实例的目录
/lib: 包含引导库
/lib/ext:JRE扩展目录
/lib/endorsed: 赞同库目录
/system: OSGi包库,作为一个Maven2存储库

Data文件夹包括karaf所有的工作和临时文件,如果你想从一个初始状态重启,你可以清空这个目录,这和“恢复初始化设置”一样的效果。
摘自: http://www.osgi.com.cn/article/7289403

karaf 使用教程:http://karaf.apache.org/manual/latest/
上面教程学习了一部分,下次有需要再看。

待解决疑惑:
felix 是如何确定 bundle 的启动级别的?
karaf 呢?它又是如何确定 bundle 的启动级别的?

第一个问题,我觉得跟 OSGI 的依赖解析规则有关,根据解析的结果,确定启动顺序。

maven,OSGI,karaf 学习笔记相关推荐

  1. maven 一个简单项目 —— maven权威指南学习笔记(三)

    目标: 对构建生命周期 (build  lifecycle),Maven仓库 (repositories),依赖管理 (dependency management)和项目对象模型 (Project O ...

  2. OSGi.NET 学习笔记 [模块化和插件化][概念]

    [目录]-[模块化和插件化]-[概念] 这算是OSGi的基础和灵魂,没有他,后面将要介绍的很多功能都会黯然失色. 先看文档怎么说: 1) 物理隔离:基于UIOSP开发的模块是一个物理隔离的可单独部署的 ...

  3. Maven慕课网学习笔记

    -唯快不破-maven快速入门 -稳扎稳打-maven核心知识 -实用为先-maven建立web项目 唯快不破-maven快速入门 Maven介绍与环境搭建 Maven是基于项目对象模型(POM),可 ...

  4. Maven相关内容学习笔记一:基本配置和使用

    首先必须推荐的这本书<Maven实战> 许晓斌,机械工业出版社 Maven简介 其实使用Maven也有很久时间了,大部分都是别人建好了工程我使用一下,实际上并没有非常详细的使用经验,这次到 ...

  5. JavaWeb学习笔记总结(一)

    前言:因为我是大三,这学期开课是JavaWeb,前端三剑客html+css+js,还有一个springboot框架的课,大二下学期才学的java跟sql,所以跨度直接到springboot有点大吧,s ...

  6. dubbo入门学习笔记之入门demo(基于普通maven项目)

    注:本笔记接dubbo入门学习笔记之环境准备继续记录; (四)开发服务提供者和消费者并让他们在启动时分别向注册中心注册和订阅服务 需求:订单服务中初始化订单功能需要调用用户服务的获取用户信息的接口(订 ...

  7. maven学习笔记之IDEA+Maven+Jetty运行一个简单的web项目

    maven学习笔记 一.什么是maven Maven是一个项目管理工具,它包含了一个项目对象模型 (Project Object Model),一组标准集合,一个项目生命周期(Project Life ...

  8. maven 学习笔记(三)创建一个较复杂的 eclipse+android+maven 工程

    前面maven 学习笔记(二)已经说过了怎样通过插件创建一个简单的工程,有了前面的基础,创建一个较复杂的工程就容易了很多.同样是通过已经有了插件,同样如果插件系统中并未存在,还是需要通过Add Arc ...

  9. Maven学习笔记__上篇

    Maven学习笔记__上篇 本文档基于 尚硅谷视频教程 整理,仅用于个人学习/交流使用. 视频链接:https://www.bilibili.com/video/BV1TW411g7hP 官方资料:链 ...

最新文章

  1. 在Linux上安装Memcached服务
  2. 才知道创建数据表的后面int(M)的m居然和存储大小没有关系
  3. 面试了一个 46 岁的程序员,我思绪万千!
  4. R语言ggplot2可视化:可视化箱图、在箱图中添加抖动数据点(Dot + Box Plot)、自定义抖动数据点的大小、颜色、数据点分布在箱图中间、添加主标题、副标题、题注信息
  5. cas协议,以及tomcat搭建cas服务器
  6. 简单实例使用_一个关于jmeter的使用简单实例
  7. google 浏览器清除缓存
  8. 饿了么翻车,美团被质疑,马云也赔了40亿,这项技术为什么让人害怕?
  9. 爬虫学习二: bs4 xpath re
  10. 两个异常:a circular reference was detected while serializing及 Maximum length exceeded
  11. Linux下autoconf与automake
  12. 理解Lucene中的Analyzer
  13. 春节见闻之北京前门步行街
  14. 细说进程、应用程序域与上下文之间的关系(三)—— 深入了解.NET上下文
  15. PID实现水平姿态角控制
  16. 一文曝光字节跳动薪资职级,资深开发的收入你意想不到~
  17. 一读就错的68个姓氏,第一个就读错了
  18. Android Studio编译报Default interface methods are only supported starting with Android N (--min-api 24)
  19. PHP开发h5棋牌源码curl用法
  20. Sentinel-2(哨兵2号)SNAP预处理

热门文章

  1. Haskell列表操作
  2. 帮助企业制作帮助文档的6大“黑科技”工具!
  3. 解决插入U盘不显示盘符问题,最有效,最简单!!!
  4. wp-admin文件下
  5. XPS文件转换PDF小工具,集成了界面,方便大家使用
  6. 直接插入排序将数字从小到大排序
  7. Linux下添加新硬盘或删除硬盘
  8. java基于微信小程序的驾校练车考试预约管理系统 uinapp 计算机毕业设计
  9. c语言字节和字的区别,字、字节、位、字长?区别?关系?
  10. itextpdf创建pdf,开箱即用