ODL中如何将配置文件打包到运行目录下

来源:互联网 发布:手机淘宝号怎么注册 编辑:程序博客网 时间:2024/06/03 15:22

目录结构

config

|----src

|       |----main

|                 |----java

|                 |----resource

|                 |            |----initial

|                 |            |          |----config-example.xml

|                 |            |----org.opendaylight.blueprint

|                 |                       |----config-blueprint.xml

|                 | ----yang          

|                               |----example-config.yang

|----pom.xml

feature

|----src

        |----main

                 |----features

                            |----feature.xml


[[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.controller</groupId>
    <artifactId>config-parent</artifactId>
    <version>0.6.0-Carbon</version>
    <relativePath/>
  </parent>
 
  <groupId>org.exampleproj</groupId>
  <artifactId>config</artifactId>
  <version>1.0.0</version>
  <name>ODL :: org.exampleproj :: ${project.artifactId}</name>
  <packaging>bundle</packaging>

  <dependencies>
...
  </dependencies>

  <!--build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Export-Package>
              org.exampleproj.config.*,
              org.opendaylight.yang.gen.v1.urn.exampleproj.config.example.config.rev171202.*
            </Export-Package>
          </instructions>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-artifacts</id>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.directory}/classes/initial/example-config.xml</file>
                  <type>xml</type>
                  <classifier>config</classifier>

                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build-->

</project>


[[example-config.yang]]

module example-config {
    yang-version 1;
    namespace "urn:exampleproj:config:example-config";
    prefix "example-config";
    
    revision "2017-12-02" {
        description "example config test";
    }

    container example-config {
        leaf name {
            type string;
        }
        leaf location {
            type string;
        }
    }
}

[[config-example.xml]]

<example-config xmlns="urn:exampleproj:config:example-config">
    <name>helloworld</name>
    <location>overseas</location>
</example-config>


[[config-blueprint.xml]]

<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
           odl:use-default-for-reference-types="true">

    <odl:clustered-app-config id="exampleConfig"
                              default-config-file-name="example-config.xml"
                              binding-class="org.opendaylight.yang.gen.v1.urn.exampleproj.config.example.config.rev171202.ExampleConfig">

    </odl:clustered-app-config>

</blueprint>


[[feature.xml]]

...

  <feature name='odl-exampleproj-config' version='${project.version}' description='OpenDaylight :: exampleproj :: exampleconfig'>
    <configfile finalname="etc/opendaylight/datastore/initial/config/example-config.xml">mvn:org.exampleproj/config/{{VERSION}}/xml/config</configfile>
    <bundle>mvn:org.exampleproj/config/{{VERSION}}</bundle>
  </feature>

...


如果不想把配置数据嵌入到config-blueprint.xml的<![CDATA[   和 ]]>,那么就把配置文件写到example-config.xml中

当程序编译之后,在karaf/target/assembly/etc下没有产生opendaylight目录

当程序运行的时候会生成这个目录karaf/target/assembly/etc/opendaylight/datastore/initial/config, 并且把example-config.xml拷贝到这个目录下

当在pom.xml中加入了controller的config-parent之后,pom.xml中的build部分注释了,example-config.xml在运行的时候是出现在想要的目录中的,所以这段注释的并没有什么影响。绿色的部分可能跟build中定义的绿色部分有关吧,存疑。

如果只是修改配置文件,如何更新配置文件测试呢?

如果配置文件在<![CDATA[   和 ]]>里面,只要替换karaf/target/assembly/system/org/exampleproj/config/1.0.0/config-1.0.0.jar包,重启karaf即可

如果配置文件已经在一个单独的文件中,并且声明了最终的文件位置是etc/opendaylight/datastore/initial/config/example-config.xml

那么需要修改karaf/target/assembly/system/org/exampleproj/config/1.0.0/config-1.0.0-config.xml,或者说覆盖此文件,

然后删掉karaf/target/assembly/etc下的opendaylight目录,如果不删掉,就不会更新,如果删掉,会把karaf/target/assembly/system/org/exampleproj/config/1.0.0/config-1.0.0-config.xml文件拷贝到etc相应的目录重命名成我们想要的文件。



参考文档

https://wiki.opendaylight.org/view/Using_Blueprint#Using_the_Datastore

http://blog.csdn.net/sonycong/article/details/49863915




原创粉丝点击