使用Maven构建过程在Ambari的metainfo.xml文件中动态创建版本号 [英] Dynamically create the version number within the Ambari's metainfo.xml file using maven build processes

查看:138
本文介绍了使用Maven构建过程在Ambari的metainfo.xml文件中动态创建版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想将服务版本硬编码到metainfo.xml中,可以吗?

I don’t want to hardcode my service version into metainfo.xml, Can I do it?

    <service>
      <name>DUMMY_APP</name>
      <displayName>My Dummy APP</displayName>
      <comment>This is a distributed app.</comment>
      <version>0.1</version> --------------This I don't want to hardcode, Can I doit?
     <components>
     ...
    </components>
  </service>

我正在使用maven作为构建工具.

I am using maven as my build tool.

推荐答案

这可以通过使用maven的资源过滤来完成.需要三个步骤:

This can be done by using maven's resource filtering. Three steps are required:

  • 定义一个将保留版本号的maven属性
  • 在metainfo.xml文件的过滤器标签之间添加该maven属性
  • 在pom中指出metainfo.xml文件需要过滤.

例如,假设您要使用与项目maven版本标识符${project.version}相同的版本,作为metainfo.xml文件中的版本.您可以将<version>0.1</version>替换为<version>${project.version}</version>.然后,在pom文件中,您需要列出该metainfo.xml文件以进行过滤.此步骤的过程将根据您捆绑定制的Ambari服务(rpm,装配等)的方式而有所不同.通常,当您列出源(包含在捆绑软件中的内容)时,无论使用哪种插件,都需要指定metainfo.xml文件的路径,并确保过滤设置为true.

For example lets assume you want to use the same version as the projects maven version identifier, ${project.version}, as your version in the metainfo.xml file. You would replace <version>0.1</version> with <version>${project.version}</version>. Then in your pom file you would need to list that metainfo.xml file as needing to be filtered. The procedure for this step will vary depending on how you are bundling the custom Ambari service (rpm, assembly, etc.). In general whichever plugin you are using when you list the sources (content to include in the bundle) you will need to specify the path to the metainfo.xml file and make sure filtering is set to true.

现在,假设您要创建一个将安装工件的rpm.看起来像这样:

Now lets assume you want to create an rpm that will install your artifact. It would look something like this:

您的项目结构应如下:

--src
  --main
    --resources
      --configuration
      --scripts
      metainfo.xml

您的pom文件如下所示:

Your pom file would look like this:

<?xml version="1.0"?>
<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>
<groupId>com.example</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>com.example.project</artifactId>
<packaging>pom</packaging>

<properties>
    <hdp.name>HDP</hdp.name>
    <hdp.version>2.3</hdp.version>
    <stack.dir.prefix>/var/lib/ambari-server/resources/stacks</stack.dir.prefix>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>rpm-maven-plugin</artifactId>
            <version>2.1.2</version>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>generate-hdp-rpm</id>
                    <phase>package</phase>
                    <goals>
                        <goal>attached-rpm</goal>
                    </goals>
                    <configuration>
                        <classifier>hdp</classifier>
                        <needarch>true</needarch>
                        <sourceEncoding>UTF-8</sourceEncoding>
                        <distribution>blah</distribution>
                        <group>something/Services</group>
                        <packager>company</packager>
                        <vendor>company</vendor>
                        <name>SERVICENAME-ambari-hdp</name>
                        <defineStatements>
                            <!-- I use the below line to prevent compiled python scripts from failing the build -->
                            <defineStatement>_unpackaged_files_terminate_build 0</defineStatement>
                            <defineStatement>platform_stack_directory ${stack.dir.prefix}/${hdp.name}/${hdp.version}</defineStatement>
                        </defineStatements>
                        <requires>
                            <require>ambari-server</require>
                        </requires>
                        <mappings>
                            <mapping>
                                <directory>${stack.dir.prefix}/${hdp.name}/${hdp.version}/services/SERVICENAME</directory>
                                <filemode>755</filemode>
                                <username>root</username>
                                <groupname>root</groupname>
                            </mapping>
                            <mapping>
                                <directory>${stack.dir.prefix}/${hdp.name}/${hdp.version}/services/SERVICENAME</directory>
                                <directoryIncluded>false</directoryIncluded>
                                <filemode>755</filemode>
                                <username>root</username>
                                <groupname>root</groupname>
                                <sources>
                                    <source>
                                        <location>src/main/resources/metainfo.xml</location>
                                        <filter>true</filter>
                                    </source>
                                </sources>
                            </mapping>
                            <mapping>
                                <directory>${stack.dir.prefix}/${hdp.name}/${hdp.version}/services/SERVICENAME/configuration</directory>
                                <filemode>755</filemode>
                                <username>root</username>
                                <groupname>root</groupname>
                            </mapping>
                            <mapping>
                                <directory>${stack.dir.prefix}/${hdp.name}/${hdp.version}/services/SERVICENAME/configuration</directory>
                                <directoryIncluded>false</directoryIncluded>
                                <filemode>755</filemode>
                                <username>root</username>
                                <groupname>root</groupname>
                                <sources>
                                    <source>
                                        <location>src/main/resources/configuration</location>
                                    </source>
                                </sources>
                            </mapping>
                            <mapping>
                                <directory>${stack.dir.prefix}/${hdp.name}/${hdp.version}/services/SERVICENAME/package</directory>
                                <filemode>755</filemode>
                                <username>root</username>
                                <groupname>root</groupname>
                            </mapping>
                            <mapping>
                                <directory>${stack.dir.prefix}/${hdp.name}/${hdp.version}/services/SERVICENAME/package/scripts</directory>
                                <filemode>755</filemode>
                                <username>root</username>
                                <groupname>root</groupname>
                            </mapping>
                            <mapping>
                                <directory>${stack.dir.prefix}/${hdp.name}/${hdp.version}/services/SERVICENAME/package/scripts</directory>
                                <directoryIncluded>false</directoryIncluded>
                                <filemode>755</filemode>
                                <username>root</username>
                                <groupname>root</groupname>
                                <sources>
                                    <source>
                                        <location>src/main/resources/scripts</location>
                                    </source>
                                </sources>
                            </mapping>
                        </mappings>
                    </configuration>
                </execution>
                <!-- You may have multiple executions if you want to create rpms for stacks other then HDP -->
            </executions>
        </plugin>
    </plugins>
</build>
<dependencies>
    <!-- List any dependencies you need -->
</dependencies>

这将创建一个rpm,安装后会将您的服务添加到HDP 2.3堆栈中.安装rpm后,您必须重新启动ambari-server以确保选择了新的服务定义.

This will create an rpm that when installed will add your service to the HDP 2.3 stack. After installing the rpm you would have to restart ambari-server to make sure the new service definition is picked up.

更新: 要为其他堆栈创建其他RPM,您将需要:

Update: To create additional RPMs for other stacks, you will need to:

  • 在pom的rpm-maven-plugin部分中复制执行块.
  • 将新执行的id元素更改为唯一.
  • 修改映射以反映其他堆栈所需的目录/文件结构.

这篇关于使用Maven构建过程在Ambari的metainfo.xml文件中动态创建版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆