我不想将我的服务版本硬编码到metainfo.xml中,我可以这样做吗?
<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作为构建工具。
答案 0 :(得分:0)
这可以通过使用maven的资源过滤来完成。需要三个步骤:
例如,假设您希望使用与项目maven版本标识符${project.version}
相同的版本作为metainfo.xml文件中的版本。您可以将<version>0.1</version>
替换为<version>${project.version}</version>
。然后在您的pom文件中,您需要将该metainfo.xml文件列为需要过滤的文件。此步骤的过程将根据您如何捆绑自定义Ambari服务(rpm,程序集等)而有所不同。通常,在列出源(要包含在包中的内容)时使用的插件中,您需要指定metainfo.xml文件的路径,并确保将过滤设置为true。
现在让我们假设您要创建一个将安装工件的rpm。它看起来像这样:
您的项目结构应如下所示:
--src
--main
--resources
--configuration
--scripts
metainfo.xml
你的pom文件看起来像这样:
<?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以确保选择新的服务定义。
更新: 要为其他堆栈创建其他RPM,您需要: