SDN-OpenDaylight(Solium版本)應用開發入門Toster

目錄

開發環境

所用資料

maven 設置

實驗步驟

構建項目

編寫toaster

再次編譯

添加toaster到opendaylight中

Postman測試


開發環境

  • VM14.0
  • Ubuntu 18.04
  • JDK1.8
  • Maven 3.6.3
  • postman

所用資料

Opendaylight-Controller(Solium版)

下載壓縮包,用clone的話下載的應該是最新版

maven 設置

cp -n ~/.m2/settings.xml{,.orig} ; wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
maven設置

實驗步驟

構建項目

進入controller-stable-sodium/opendaylight/md-sal/samples

在該目錄下執行以下命令

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

耗時2-3分鐘...

構建成功

 

編寫toaster

添加一個名爲features的module

打開項目,在samples目錄下的pom.xml中添加名爲features的module,如下圖

添加features

在features目錄下添加pom.xml,內容如下

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> 
 
    <parent>         
		<groupId>org.opendaylight.odlparent</groupId>         
		<artifactId>odlparent-lite</artifactId>         
		<version>5.0.5</version>
		<relativePath/>
	</parent> 
 
    <groupId>org.opendaylight.controller.samples</groupId>
	<artifactId>mytoaster-features-aggregator</artifactId>
	<version>1.10.3-SNAPSHOT</version>
	<packaging>pom</packaging>
	<name>org.opendaylight.controller.samples :: ${project.artifactId}</name>
 
    <modules>
		<module>odl-mytoaster</module>
		<module>odl-mytoaster-provider</module>
		<module>features-mytoaster</module> 
    </modules> 
</project>

 

在features中添加三個目錄,odl-mytoaster,odl-mytoster-provider,features-mytoaster。

mkdir odl-mytoaster odl-mytoster-provider features-mytoaster

 

添加前
添加後

 之後,在三個目錄下分別添加pom.xml文件,內容如下

odl-mytoaster下的pom.xml文件內容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.opendaylight.odlparent</groupId>
    <artifactId>feature-repo-parent</artifactId>
    <version>5.0.5</version>
    <relativePath/>
  </parent>

  <groupId>org.opendaylight.controller.samples</groupId>
  <artifactId>features-mytoaster</artifactId>
  <version>1.10.3-SNAPSHOT</version>
  <packaging>feature</packaging>
  <name>ODL::org.opendaylight.mytoaster::${project.artifactId}</name>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>odl-mytoaster-provider</artifactId>
      <version>${project.version}</version>
	  <type>xml</type>
	  <classifier>features</classifier>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>odl-mytoaster</artifactId>
	  <version>${project.version}</version>
	  <type>xml</type>
	  <classifier>features</classifier>
    </dependency>
  </dependencies>
</project>

odl-mytoaster下的pom.xml內容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.opendaylight.odlparent</groupId>
    <artifactId>single-feature-parent</artifactId>
    <version>5.0.5</version>
    <relativePath/>
  </parent>

  <groupId>org.opendaylight.controller.samples</groupId>
  <artifactId>odl-mytoaster</artifactId>
  <version>1.10.3-SNAPSHOT</version>
  <packaging>feature</packaging>
  <name>OpenDaylight::mytoaster::Impl[Karaf Feature]</name>

  <dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.opendaylight.controller</groupId>
			<artifactId>mdsal-artifacts</artifactId>
			<version>1.10.2</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
  </dependencyManagement>
  <dependencies>
	<dependency>
		<groupId>org.opendaylight.controller</groupId>
		<artifactId>odl-mdsal-broker</artifactId>
		<type>xml</type>
		<classifier>features</classifier>
	</dependency>
	<dependency>
		<groupId>${project.groupId}</groupId>
		<artifactId>sample-toaster</artifactId>
		<version>${project.version}</version>
	</dependency>
  </dependencies>

</project>

features-mytoaster的內容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.opendaylight.odlparent</groupId>
    <artifactId>single-feature-parent</artifactId>
    <version>5.0.5</version>
    <relativePath/>
  </parent>

  <groupId>org.opendaylight.controller.samples</groupId>
  <artifactId>odl-mytoaster-provider</artifactId>
  <version>1.10.3-SNAPSHOT</version>
  <packaging>feature</packaging>
  <name>OpenDaylight::mytoaster::Impl[Karaf Feature]</name>

  <dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.opendaylight.controller</groupId>
			<artifactId>mdsal-artifacts</artifactId>
			<version>1.10.2</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
  </dependencyManagement>

  <dependencies>
	<dependency>
		<groupId>org.opendaylight.controller</groupId>
		<artifactId>odl-mdsal-broker</artifactId>
		<type>xml</type>
		<classifier>features</classifier>
	</dependency>
	<dependency>
		<groupId>${project.groupId}</groupId>
		<artifactId>sample-toaster</artifactId>
		<version>${project.version}</version>
	</dependency>
		<dependency>
		<groupId>${project.groupId}</groupId>
		<artifactId>sample-toaster-provider</artifactId>
		<version>${project.version}</version>
	</dependency>
  </dependencies>

</project>

再次編譯

進入controller-stable-sodium/opendaylight/md-sal/samples

在該目錄下再次執行以下命令

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

耗時5分半...

再次編譯成功

添加toaster到opendaylight中

我選擇了上篇文章SDN-OpenDaylight(Solium版本)應用開發入門HelloWorld中創建的helloworld項目。

在helloworld/karaf/target/assembly/system/org/opendaylight/controller下創建一個名爲 samples的目錄在改目錄中創建如下幾個文件夾 features-mytoaster odl-mytoaster-consumer sample-toaster-consumer features_mytoaster odl-mytoaster-provider sample-toaster-provider odl-mytoaster  sample-toaster

mkdir samples
cd samples
mkdir features-mytoaster odl-mytoaster-consumer sample-toaster-consumer features_mytoaster odl-mytoaster-provider sample-toaster-provider odl-mytoaster sample-toaster
添加目錄

在每個目錄中創建和 toaster 項目中對應 module version 相同名稱的目錄,即創建1.10.3-SNAPSHOT目錄

mkdir 1.10.3-SNAPSHOT
其他目錄也有,共8個

在 odl 開頭的目錄中(odl-mytoaster、odl-mytoaster-provider),將前面 toaster 構建的 target目錄 中找到 feature目錄並將其每一個目錄中的feature.xml放入創建的和版本名相同的目錄(1.10.3-SNAPSHOT)中

使用cp命令

在以 sample 開頭的目錄(三個)中放入對應模塊構建的 jar 包,不要結尾有sources的,另外兩個同理。

添加jar包
feature:repo-add mvn:org.opendaylight.controller.samples/features-mytoaster/1.10.3-SNAPSHOT/xml/features
添加mytoaster
顯示mytoaster已安裝

Postman測試

未做麪包
製作麪包
麪包機工作,製作數量爲1

更多SDN相關內容,請查看:SDN-自學筆記

有問題請下方評論,轉載請註明出處,並附有原文鏈接,謝謝!如有侵權,請及時聯繫。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章