...
The Stack definitions can be found in the source tree at /ambari-server/src/main/resources/stacks
. After you install the Ambari Server, the Stack definitions can be found at /var/lib/ambari-server/resources/stacks
...
Stack Properties
The structure of a Stack definition is as follows:stack must contain or inherit a properties directory which contains two files: stack_features.json and stack_tools.json. The properties directory must be at the root stack version level and must not be included in the other stack versions. This directory is new in Ambari 2.4.
The stack_features.json contains a list of features that are included in Ambari and allows the stack to specify which versions of the stack include those features. The list of features are determined by the particular Ambari release. The reference list for a particular Ambari version should be found in the HDP/2.0.6/properties/stack_features.json in the branch for that Ambari release. Each feature has a name and description and the stack can provide the minimum and maximum version where that feature is supported.
{
"stack_features": [
{
"name": "snappy",
"description": "Snappy compressor/decompressor support",
"min_version": "2.0.0.0",
"max_version": "2.2.0.0"
},
...
}
The stack_tools.json includes the name and location where the stack_selector and conf_selector tools are installed.
{
"stack_selector": ["hdp-select", "/usr/bin/hdp-select", "hdp-select"],
"conf_selector": ["conf-select", "/usr/bin/conf-select", "conf-select"]
}
For more information see the Stack Properties wiki page.
Structure
The structure of a Stack definition is as follows:
Code Block |
---|
|_ stacks
|_ <stack_name>
|_ <stack_version>
metainfo.xml
|
Code Block |
|_ stacks
|_ <stack_name>
|_ <stack_version>
metainfo.xml
|_ hooks
|_ repos
repoinfo.xml
|_ services
|_ <service_name>
metainfo.xml
metrics.json
|_ configuration
{configuration files}
|_ package
{files, scripts, templates} |
...
- In Ambari Web, browse to Services and click the Actions button in the Service navigation area on the left.
- The "Add Services" wizard launches. You will see an option to include "My Sample Service" (which is the
<displayName>
of the service as defined in the servicemetainfo.xml
file). - Select "My Sample Service" and click Next.
- Assign the "Sample Srv Master" and click Next.
- Select the hosts to install the "Sample Srv Client" and click Next.
- Once complete, the "My Sample Service" will be available Service navigation area.
- If you want to add the "Sample Srv Client" to any hosts, you can browse to Hosts and navigate to a specific host and click "+ Add".
Example: Implementing a Custom Client-only Service
In this example, we will create a custom service called "TESTSRV", add it to an existing Stack definition and use the Ambari APIs to install/configure the service. This service is a CLIENT so it has two commands: install and configure.
Create and Add the Service
- Service" and click Next.
- Assign the "Sample Srv Master" and click Next.
- Select the hosts to install the "Sample Srv Client" and click Next.
- Once complete, the "My Sample Service" will be available Service navigation area.
- If you want to add the "Sample Srv Client" to any hosts, you can browse to Hosts and navigate to a specific host and click "+ Add".
Example: Implementing a Custom Client-only Service
In this example, we will create a custom service called "TESTSRV", add it to an existing Stack definition and use the Ambari APIs to install/configure the service. This service is a CLIENT so it has two commands: install and configure.
Create and Add the Service
On the Ambari Server, browse to the
/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services
directory. In this case, we will browse to the HDP 2.0 Stack definition.Code Block cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services
Create a directory named
/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV
that will contain the service definition for TESTSRV.
On the Ambari Server, browse to theCode Block mkdir
directory. In this case, we will browse to the HDP 2.0 Stack definition./var/lib/ambari-server/resources/stacks/HDP/2.0.6/services
Code Block /TESTSRV cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services
Create a directory named
/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV
that will contain the service definition for TESTSRV.Code Block mkdir /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV
/HDP/2.0.6/services/TESTSRV
Browse to the newly created
TESTSRV
directory, create ametainfo.xml
file that describes the new service. For example:Code Block <?xml version="1.0"?> <metainfo> <schemaVersion>2.0</schemaVersion> <services> <service> <name>TESTSRV</name> <displayName>New Test Service</displayName> <comment>A New Test Service</comment> <version>0.1.0</version> <components> <component> <name>TEST_CLIENT</name> <displayName>New Test Client</displayName> <category>CLIENT</category> <cardinality>1+</cardinality> <commandScript> <script>scripts/test_client.py</script> <scriptType>PYTHON</scriptType>
Browse to the newly created
TESTSRV
directory, create ametainfo.xml
file that describes the new service. For example:Code Block <?xml version="1.0"?> <metainfo> <schemaVersion>2.0</schemaVersion> <services> <service> <name>TESTSRV<<timeout>600</name>timeout> <displayName>New Test Service</displayName> </commandScript> <comment>A New Test Service</comment> <version>0.1.0</version> <customCommands> <components> <customCommand> <component> <name>TEST_CLIENT<<name>SOMETHINGCUSTOM</name> <displayName>New Test Client</displayName> <commandScript> <category>CLIENT</category> <script>scripts/test_client.py</script> <cardinality>1+</cardinality> <scriptType>PYTHON</scriptType> <commandScript> <timeout>600</timeout> <script>scripts/test_client.py</script></commandScript> <scriptType>PYTHON<</scriptType>customCommand> <timeout>600</timeout> </customCommands> </component> </commandScript> </components> <customCommands><osSpecifics> <osSpecific> <customCommand> <osFamily>any</osFamily> <!-- note: use osType rather than osFamily for <name>SOMETHINGCUSTOM</name> Ambari 1.5.0 and 1.5.1 --> </osSpecific> <commandScript> </osSpecifics> </service> <script>scripts/test_client.py</script> <scriptType>PYTHON</scriptType> <timeout>600</timeout> </commandScript> </customCommand> </customCommands> </component> </components> <osSpecifics> <osSpecific> <osFamily>any</osFamily> <!-- note: use osType rather than osFamily for Ambari 1.5.0 and 1.5.1 --> </osSpecific> </osSpecifics> </service> </services> </metainfo>
- In the above, my service name is "TESTSRV", and it contains one component "TEST_CLIENT" that is of component category "CLIENT". That client is managed via the command script
scripts/test_client.py
. Next, let's create that command script. Create a directory for the command script
/var/lib/ambari-server/resources/stacks/HDP/2.0.6/servi
ces/
TESTSRV
/
package/scripts
that we designated in the service metainfo.Code Block mkdir -p /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV/package/scripts cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV/package/scripts
Browse to the scripts directory and create the
test_client.py
file. For example:Code Block import sys from resource_management import * class TestClient(Script): def install(self, env): print 'Install the client'; def configure(self, env): print 'Configure the client'; def somethingcustom(self, env): print 'Something custom'; if __name__ == "__main__": TestClient().execute()
</services> </metainfo>
- In the above, my service name is "TESTSRV", and it contains one component "TEST_CLIENT" that is of component category "CLIENT". That client is managed via the command script
scripts/test_client.py
. Next, let's create that command script. Create a directory for the command script
/var/lib/ambari-server/resources/stacks/HDP/2.0.6/servi
ces/
TESTSRV
/
package/scripts
that we designated in the service metainfo.Code Block mkdir -p /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV/package/scripts cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV/package/scripts
Browse to the scripts directory and create the
test_client.py
file. For example:Code Block import sys from resource_management import * class TestClient(Script): def install(self, env): print 'Install the client'; def configure(self, env): print 'Configure the client'; def somethingcustom(self, env): print 'Something custom'; if __name__ == "__main__": TestClient().execute()
Now, restart Ambari Server for this new service definition to be distributed to all the Agents in the cluster.
Code Block ambari-server restart
Now, restart Ambari Server for this new service definition to be distributed to all the Agents in the cluster.
Adding Repository details in repoinfo.xml
When adding a custom service, it may be needed to add additional repository details for the stack especially if the service binaries are available through a separate repository. Additional <repo> entries can be added and Ambari will ensure that the base URL provided is used to create repo files on the hosts where service is being installed.
<reposinfo> <repo> <repo> |
---|
Install the Service (via the Ambari REST API)
...