...
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.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
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> <timeout>600</timeout> </commandScript> <customCommands> <customCommand> <name>SOMETHINGCUSTOM</name> <commandScript> <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()
Now, restart Ambari Server for this new service definition to be distributed to all the Agents in the cluster.
Code Block ambari-server restart
...
- 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 Test Service" (which is the
<displayName>
of the service as defined in the servicemetainfo.xml
file). - Select "My Test Service" and click Next.
- Select the hosts to install the "New Test Client" and click Next.
- Once complete, the "My Test Service" will be available Service navigation area.
- If you want to add the "New Test 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 (with Configs)
In this example, we will create a custom service called "TESTCONFIGSRV" and add it to an existing Stack definition. This service is a CLIENT so it has two commands: install and configure. And the service also includes a configuration type "test-config".
Create and Add the Service to the Stack
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/TESTCONFIGSRV
that will contain the service definition for TESTCONFIGSRV.Code Block mkdir /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTCONFIGSRV cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTCONFIGSRV
Browse to the newly created
TESTCONFIGSRV
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>TESTCONFIGSRV</name> <displayName>New Test Config Service</displayName> <comment>A New Test Config Service</comment> <version>0.1.0</version> <components> <component> <name>TESTCONFIG_CLIENT</name> <displayName>New Test Config Client</displayName> <category>CLIENT</category> <cardinality>1+</cardinality> <commandScript> <script>scripts/test_client.py</script> <scriptType>PYTHON</scriptType> <timeout>600</timeout> </commandScript> </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 "TESTCONFIGSRV", and it contains one component "TESTCONFIG_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/
TESTCONFIGSRV
/
package/scripts
that we designated in the service metainfo<commandScript>
.Code Block mkdir -p /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTCONFIGSRV/package/scripts cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTCONFIGSRV/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 config client'; def configure(self, env): print 'Configure the config client'; if __name__ == "__main__": TestClient().execute()
Now let's define a config type for this service. Create a directory for the configuration dictionary file
/var/lib/ambari-server/resources/stacks/HDP/2.0.6/servi
ces/
TESTCONFIGSRV
/
configuration
.Code Block mkdir -p /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTCONFIGSRV/configuration cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTCONFIGSRV/configuration
Browse to the configuration directory and create the
test-config.xml
file. For example:Code Block <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>some.test.property</name> <value>this.is.the.default.value</value> <description>This is a kool description.</description> </property> </configuration>
Now, restart Ambari Server for this new service definition to be distributed to all the Agents in the cluster.
Code Block ambari-server restart